PEP308 - preference for 'x if c else y' over 'c then x else y'

Erik Max Francis max at
Sat Feb 15 07:25:23 CET 2003

Stephen Horne wrote:

> The '... if ... else ...' version seems to have a natural
> repetition-based pattern of growth which need not rely on obvious
> nesting...
>   x if c1 else y if c2 else z
> OK, yes, it is nesting really - but, like the C 'else if', it reads
> more like a continuation of the same thing than a nesting of one thing
> in another.

I really don't follow.  I would argue exactly the opposite:  Since
if/else doesn't read left-to-right, the use of it for nesting (they're
nesting both ways, however you want to look at it) is _more_
strightforward on the strict left-to-right ordering of then/else than on
the center-left-right one.  In the center-left-right one, it is harder
to tell which condition belongs to what expressions due to the out of
order pattern.

All I see here is, "X strikes me as better than Y" -- which don't get me
wrong, is a perfectly valid opinion -- but I really don't see any
clarification of why.

 Erik Max Francis / max at /
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ A man's life is what his thoughts make it.
\__/ Marcus Aurelius
    Fauxident /
 A "faux" ident daemon in Python.

More information about the Python-list mailing list