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

Eric S. Raymond esr@thyrsus.com
Sun, 30 Jan 2000 20:07:11 -0500


Christopher Petrilli <petrilli@amber.org>:
> The question comes from what "problem" you're trying to solve.  The ?: syntax
> does not introduce any new "functionality" to the language, nor does it
> make it capable of solving problems or requirements that it can not do
> at the current time.

Well, in a theoretical sense, you're right.  But then, even troff macros and
INTERCAL are Turing-complete <my-first-attempt-at-a-Tim-Peters-style-wink>.

One of the lessons of Python to this old LISPer is that *notation
matters*.  Theoretically, Python is a subset of Scheme-with-objects
using a vaguely C-like surface notation.  But even I would rather write
a for-loop than the equivalent recursion.  That's why I code in Python
now instead of trying to rescue LISP from its desuetitude.

So while it is *theoretically* true that ?: adds nothing, it is
*practically* true that it enables a large class of idioms that 
can't otherwise be comfortably expressed.  That matters.

Now, you can argue that the complexity ?: adds to language is not paid
for by the additional convenience; I disagree, but that's at least a
defensible argument.  But simply saying it "adds nothing to the
language" is a red herring -- neither do many of the other base
language features.

Why, for example, do we have more than one kind of loop construct?
Unecessary.  Wasteful.  Clearly either "for" or "while" must go.
As an exercise, try editing your complaint so that it refers to 
"for" everywhere it now refers to ?:.  Contemplate the edited
version until you achieve enlightenment ;-).
-- 
		<a href="http://www.tuxedo.org/~esr">Eric S. Raymond</a>

The same applies for other kinds of long-lasting low-level pain. [...]
The body's response to being jabbed, pierced, and cut is to produce
endorphins. [...]  So here's my programme for breaking that cycle of
dependency on Windows: get left arm tattooed with dragon motif, buy a
crate of Jamaican Hot! Pepper Sauce, get nipples pierced.  With any
luck that will produce enough endorphins to make Windows completely
redundant, and I can then upgrade to Linux and get on with things.
	-- Pieter Hintjens