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

Jamie Guinan guinan at bluebutton.com
Fri Feb 7 20:49:58 CET 2003


On Fri, 07 Feb 2003 12:14:40 -0500, Guido van Rossum wrote:

> Proposal
> 
>     The proposed syntax is as follows:
> 
>         <expression1> if <condition> else <expression2>

This reminds me of an idiom from another language,

   big-long-complicated-expression unless simple-test-expression;

which I really dislike because after mentally parsing the
"big-long-complicated-expression" I hit the "unless
simple-test-expression" part and I have to backtrack and think "oh, 
that first thing might not happen after all".  Little annoyances 
like that add up, and make code harder to read.  I like the fact 
that Python keeps things simple and consistent, and I'm perfectly
happy to trade the conciseness offered by this proposed
syntax for the clarity of doing it "the long way",

    if simple-test-expression:
        big-long-complicated-expression
    else:
        ...

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

That looks like "one more way to do it" for simple if/else clauses.
Python's "only one obvious way to do it" philosophy is one 
of its big advantages in being easy to learn, and making 
existing code easy to read and maintain.  I would hate to
see it drift toward timtowtdi...

-Jamie




More information about the Python-list mailing list