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

Stephen Horne intentionally at blank.co.uk
Sat Feb 15 10:38:14 CET 2003


On Sat, 15 Feb 2003 00:54:56 -0800, Erik Max Francis <max at alcyone.com>
wrote:

>I'm not "preoccupied" with it, I just think it impairs understanding. 
>If you've also been reading these threads, you'd see that this was a
>wide-reaching objection, penetrating both pro- and anti-PEP camps.  Lots
>of people objected to it, not just me.

OK - "preoccupied" was a bad choice of words.


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.

Unary and binary operators are great, but with longer syntactic
structures I like to be told at the start what is coming. There is
basically a limit to how much my brain can parse at a glance. I said
something similar when I suggested 'either' as a prefix for '... if
... else ...'. There comes a point when I have to consciously read
from left to right (without that implying an execution order) and an
explicit leading keyword makes life easy.


Getting back to the point, though - personally, I tend to agree with
those who say the reading order issue is one of familiarity rather
than anything more fundamental, but I do see your point.

-- 
steve at ninereeds dot fsnet dot co dot uk




More information about the Python-list mailing list