For review: PEP 308 - If-then-else expression

Manuel Garcia news at manuelmgarcia.com
Tue Feb 11 20:09:39 EST 2003


+1 for if-then-else expression

+1 for short-circuiting

+1 for (<condition> ?? <expression1> || <expression2>)

+1 for requiring the parentheses

-----------------

The biggest benefit to having the if-then-else expression is that we
can toss out this lousy idiom:

    (<false>,<true>)[<condition>]

I don't use this idiom, but I have seen it in the wild.

I don't know who had the idea for using ?? ||, but I like it.

?? || are nice for keeping expressions looking like expressions.  "if"
"else" would make expressions look too much like statements.

This is the format I wish I could use:

   (<condition> ?? <expression1> || <expression2>)

where the parentheses are required.  If parentheses are required, it
is easy to figure out else-expressions, even with nesting.  With other
people's code, using a text editor with matching-brace highlighting,
it is trivial.

Short-circuiting would be the least astonishing behavior.  Once people
understand short-circuiting for "and" "or", ( ?? || ) is not much more
difficult to understand.




More information about the Python-list mailing list