[Python-Dev] Adding a conditional expression in Py3.0

Michael Chermside mcherm at mcherm.com
Thu Sep 29 22:31:46 CEST 2005

[ongoing discussion of conditional expressions]

I waited until I had caught up on my reading before saying anything. Now I'll
express my opinion in a single posting then keep quiet unless I actually find I
have something novel to contribute (difficult in a topic that's been talked to
death 3 or 4 times in the past few years).

 * I am STRONGLY in favor of introducing a conditional expression in some
   form. The use of the "and-or" trick is proof enough to me that there is
   a need for it. I can marshall other arguments also, but they appear

 * The syntax to use is a place where we need a BDFL decision. Make the
   decision and we'll all agree and move on. Any decision would be better
   than an eternity of re-discovering old ideas again and again.

 * I think the two best options are
       trueval if cond else falseval
       if cond then trueval else falseval
   The first has brevity in it's favor, and "cleverness" which might be
   an advantage or disadvantage depending on your point of view. The
   second has order-of-arguments in its favor. In either case, wise
   programmers will use parenthesees when it aids clarity (imagine
   "v1 if c else v2 + v3"). Whether we require parenthesees when the
   parser could disambiguate on its own is really up to Guido.

 * I prefer the second form ("if cond then trueval else falseval")
   because it puzzles _nobody_ at the expense of being slightly
   more wordy and less clever. But that's just one person's opinion.

Thanks Guido, for maintaining your patience in the face of this

-- Michael Chermside

More information about the Python-Dev mailing list