[Python-Dev] vox populii illiterati

Neal Norwitz neal@metaslash.com
Sun, 09 Feb 2003 11:51:10 -0500


On Sun, Feb 09, 2003 at 10:39:28AM -0500, Guido van Rossum wrote:
> > Nobody will try to sort out the votes from the well over 
> > 600 postings (and growing).
> 
> Ouch.  And it's only Sunday morning here.  That exceeds my wildest
> expectations.
> 
> Is anybody at least collecting useful feedback?  I'm willing to update
> the PEP to at least mention sensible alternatives or arguments pro and
> con, but I can't read the c.l.py messages.

I have read most of the posts.  It's a bit humorous to watch emotions
get so stirred in both directions.  It seems there are many
python-devers following the discussion: Aahz, Andrew Koenig (ARK),
Michael Hudson, Holger Krekel, and Tim have all posted.  ARK seems
to be the most pro, Aahz the most against.  (I'm +0 on having
a ternary operator in theory, -1 on PEP 308.)

ARK can do the best job of summarizing the pro-side, but the
strongest arguments I've seen are that using a ternary op can
reduce bugs by not duplicating a variable on assignment:

        if cond:
                x = true_value
        else:
                x = false_value

vs. (in C notation):
        x = cond ? true_value : false_value

Since x is only mentioned once, you can't get it wrong.

Part of the reason for using if-expressions (the ternary op) is the
programmer has a different mindset.  They aren't thinking about
control (as in an if statement).  They are thinking about an
expression and the ternary operator allows them to program what they
are thinking.  It also would be usable in lambdas.  Many against feel
that using a conditional (if) is always control.  (I'm generalizing a
bit.)

One thing to note, many people are saying you can currently do:

        cond and true_value or false_value

However, many have gotten it wrong, either by reversing the true/false
value or by using something in the true_value which may be false
(sometimes even constants).  pychecker tries to find this condition
(when true_value is a false constant), but it does a poor job
of determining the idiom IIRC.

Neal