PEP308 - preference for 'x if c else y' over 'c then x else y'
Erik Max Francis
max at alcyone.com
Sat Feb 15 05:06:09 EST 2003
Stephen Horne wrote:
> I'm still catching up on these threads, I admit. I just spotted a
> suggestion you made which makes a lot of sense to me... the 'if ...
> then ... else ...'. Looking back, I already used it (accidentally) in
> my first post in this thread when I intended to use the '... then ...
> else ...' form. It's still a ternary operator, but the leading 'if'
> warns you what's coming and makes a big difference to readability.
The `if C then x else y' form was originally listed as an alternative in
the PEP. Its main point of contention was that the use of `if' made it
_harder_ to read, since it could be confused with an `if' statement. I
personally don't buy into that argument, but that's mainly where the `C
then x else y' alternative came from. That is, it came about precisely
because some weren't satisfied with the alternative you're suggesting
(which, again, was in the PEP originally).
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ No one should have to dance backward all their lives.
\__/ Jill Ruckelshaus
WebVal / http://www.alcyone.com/pyos/webval/
URL scanner, maintainer, and validator in Python.
More information about the Python-list
mailing list