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

Eru ripolles at
Fri Feb 7 21:03:45 CET 2003

Guido van Rossum <guido at> escribio:
> Proposal
>    The proposed syntax is as follows:
>        <expression1> if <condition> else <expression2>

If I may give my opinion, I don't like much that syntax. I think it
introduces too much "potential obfuscation". I think it's too perlish
to be pythonic. And if we add the "empty else" option (A if condition)
it starts getting difficult to read. I prefer that obfuscation and 
oneliners keep being hard to get

> Alternatives
>    Many C-derived languages use this syntax:
>        <condition> ? <expression1> : <expression2>
>    I reject this for several reasons: the colon already has many uses
>    in Python (even though it would actually not be ambiguous, because
>    the question mark requires a matching colon); for people not used
>    to C-derived language, it is hard to understand.
>    Eric Raymond proposed a variant that doesn't have this problem:
>        <condition> ? <expression1> ! <expression2>

I would prefer the a?b:c way. It doesn't introduce new punctuation (which
leds to more difficulty when explaining the syntax, and remembering it).
Furthermore, I don't think it's difficult to read, though I may not be very
objective about this since I've used C for quite some time.
It's also quite compact, and somehow intuitive for most seasoned programmers,
while not strictly needed for beginners.

>    While cute, this suffers from the Perlish problem of using
>    arbitrary punctuation with an arbitrary meaning; and it's no
>    easier to understand than the ?: form.

I agree with that one.

>    If we could live with adding a new keyword, we could use:
>        if <condition> then <expression1> else <expression2>

Mmm, introducing a new keyword can be a problem, and I don't think it's a good
idea in this case. Moreover, it isconfusingly similar to the 'normal' syntax;
it could led to problems like doubting when 'then' is needed and when it must
not be used.

How about 

if condition : expression1 else expression2

If that's not suitable for any reason (I haven't actually thought carefully 
about the side effects), I prefer the a?b:c option

Daniel Ripolles ( Eru )
There are only two things that smell like fish.
One of them is fish

More information about the Python-list mailing list