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

David Ascher dascher@mindspring.com
Sun, 30 Jan 2000 16:09:39 -0800


> > 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 personally haven't been stunned by the ample evidence you mention.  While
folks do ask about the ternary select periodically in classes and on the
net, none of my students at least are especially upset when I point out the
readability of:

if a:
      b = c
else:
      b = d

> 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.

The presumption from the language design point of view is to do what's right
regardless of language background, not what's in C -- when Guido remembered
that, he chose 'and' and 'or' over '&&' and '||'.  When Guido forgot that,
he chose integer division =).  While all of the folks on this list are
comfortable with C, I can point out that a (possibly surprisingly) large
proportion of the Python programmers I have taught have never used C or
never felt comfortable with it. If CP4E succeeds, that proportion will grow,
not shrink.

I do think that taking a page from Randy Pausch would be a good idea in this
case.  My guess is that english words would emerge from trying to teach
non-programmers the concept, but I of course don't have data on the topic.
I wonder how high-school teachers teach the hook-colon in C intro classes,
specifically what _words_ they use.  Those words might lead to alternative
syntaxes.

Finally, something at the edge of my brain is trying to combine the logic of
the ternary select (which is clearly related to control flow) and a more
generalized switch statement.  But I'm not seeing anything syntactically
appealing at present.

That said, the hook-colon syntax is appealing from a release management
perspective because it fits within the current set of reserved words and
clearly isn't the hardest concept to teach.

--david