PEP 308: I liked the original proposal better

Dan Schmidt dfan at dfan.org
Fri Feb 14 09:25:47 EST 2003


"Greg Ewing (using news.cis.dfn.de)" <me at privacy.net> writes:

| I'd like to put in a plea for re-instatement of the original
| proposal
|
|     x if C else y
|
| which I found to be particularly elegant. It's concise,
| it reads well, it means just what it says, it resonates
| with similar constructs in English and mathematics. It
| slots nicely into the syntax without requiring any new
| reserved words ("else" can be a pseudo-keyword). Its
| meaning should be dead obvious even to someone who's
| never seen it before.

I liked it best too, but when Guido seemed to give up on it then I did
too.

The one thing I don't like is that

   a = x if C else y

reads to me from my Perl and Ruby experience as

   (a = x) if C else y

and I would prefer

   a = (x if C else y)

to be required (and the first statement to be parsed as the second and
thus be syntax error), although I'd prefer to leave out the parentheses
in

   a = func( x if C else y )

and 

   a = func( arg1, x if C else y, arg3 )

I haven't taken the time to find out whether Python's list of operator
precedence is ordered in such a way that that would be possible.

Dan

-- 
http://www.dfan.org




More information about the Python-list mailing list