[Python-Dev] Adding C ternary select (a?b:c) to Python?

Tim Peters tim_one@email.msn.com
Sun, 30 Jan 2000 19:44:34 -0500


[Tim, tosses off   cond "?" true "else" false
 in apparent hatred of colons]

[Eric S. Raymond]
> I have to say that I think any ternary syntax that mixes a
> single-character operator with a keyword would be intolerably ugly.

It's certainly not attractive <wink>.  Guido is the Master of Syntax; if he
decides the functionality is Pythonic, he'll dream up a good Pythonic
syntax.  I'll refrain from suggesting  "if" cond "lambda" true "else" false
<wink>.

>> Now let's see whether people really want the functionality or are just
>> addicted to C syntax <ahem>.

> It's not that simple.  People clearly want the functionality; we've
> seen ample evidence of that.

I have not.  Really!  This has been debated for nearly a decade, with no
consensus (the invention of the (a and [b] or [c])[0] atrocity predates
c.l.py!).  *Some* people certainly want ?: (or equivalent) a lot; but others
are equally opposed.  Note that lack of ?: didn't have enough of a
constituency in Andrew Kuchling's eyes either to make his original "Python
Warts" paper, or its revisions:

    http://starship.python.net/crew/amk/python/writing/warts.html

No change ever proposed has failed to attract vocal & persistent supporters,
so it's not as simple as *that* either <0.5 wink>.

> Given that, I think the presumption has to be in favor of using the
> familiar C syntax rather than an invention that would necessarily be
> more obscure.

By count, I'm sure many more languages (from virtually all functional
languages to Icon) use "if cond then true else false" for this purpose;
obscurity is relative to your background.  At least "if x then y else z" is
clear on the face of it (which may betray my background <wink>).  "then" has
no chance of getting into Python1, though.

My core objection is that ?: doesn't "look pretty":  it's not at all
suggestive of what it means, and the effects on precedence and associativity
are unattractive ("see C, copy C" is the only sense there is to it, and
rules for ?: are-- as I noted last time --obscure).  Good syntax counts for
a lot in Python -- which is why it doesn't look like C now.

Get a good syntax, and most of my objections vanish; I don't have a good
syntax to suggest, though.

passing-the-ball-back-to-guido-where-he-always-knew-it-
    would-land<wink>-ly y'rs  - tim