Defending the ternary operator

Alexander Schmolck a.schmolck at gmx.net
Mon Feb 10 16:30:12 EST 2003


kaz at ashi.footprints.net (Kaz Kylheku) writes:

> <cribeiro at mail.inet.com.br> wrote in message news:<mailman.1044678564.8549.python-list at python.org>...
> > Why is a ternary operator needed? The main reason is that it allows the
> > programmer to clearly express his intentions.
> 
> Once upon a time a programming language was invented which
> artificially divided computation into statements, which directed the
> control flow, and expressions, which evaluated formulas. The creators
> looked upon the language, and thanks to their inexperience saw that it
> was not bad.
> 
> In reality, this division into statements and expressions is nonsense.
> You want evaluation control in expressions, which is why the C
> language has operators like comma, &&, || and the ternary operator.
> 
> The real solution is not to divide the language into expressions and
> statements, just have expressions. Then you don't run into stupid
> problems, like not being able to use a statement where an expression
> is expected. The role of statements is usurped by constructs which
> are, syntactically, expressions, but which like the ternary operator
> have special evaluation rules.

I've expected this argument and I find it difficult to brush aside completely
if each statement type over the years sprouts a strangely differently looking
expression offshoot (lambdas, list comprehensions, "ternary"s).

BTW, have you programmed in python?

alex




More information about the Python-list mailing list