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

Paul F. Dubois dubois at users.sourceforge.net
Sat Feb 8 19:40:49 CET 2003


"Dave Brueck" <dave at pythonapocrypha.com> wrote in message
news:mailman.1044726939.7430.python-list at python.org...
> I guess I'm just emphasizing that, for or against the PEP, we should all
> be careful about including "increased readability" in our list of reasons
> - if you had been using if-expressions all along you would probably
> consider them to be quite readable. Now, exuse me while I go argue some
> more that if-exprs can make code more readable. ;-)
>
I remember all the people who wrote that list comprehensions were
unreadable. Curious, when I recently presented this to a room full of
scientists who use Python as a new feature, all I heard was, "Oh, Thank
God!".

I think we should distinguish the amount of cognitive effort involved to see
the meaning of something. People who argue that one can already say  things
like

condition and xor y

are assuming the reader posseses a knowlege of the semantics of the 'and'
and 'or' (for example, that condition and x is x if condition is true,
whereas it might well be a 1 if you don't know otherwise) and the and/or
precedence. Sure, I can figure it out, but that isn't the point. The point
is, can I read it without employing too much of my higher-level thinking
processes.

By contrast,

x if condition else y

requires learning the thing once, after which it would be really hard to
mistake it.








More information about the Python-list mailing list