Defending the ternary operator

Martin Maney maney at pobox.com
Sun Feb 9 23:11:33 EST 2003


David Eppstein <eppstein at ics.uci.edu> wrote:
> My impression is that a ternary operator is already used, often, in the 
> guise of "x and y or z" or "[z,y][x]" or still worse 
> "[lambda:y,lambda:z][not x]()". Introducing a true ternary operator 
> might at least prevent programmers from committing such atrocities.

Better yet, it would save otherwise kind and compassionate people from
having to foist these wretches off on the innocent who come to them for
assistance.

> But, programmers uninterested in writing readable code will anyway find 
> other ways to be unreadable.  What I am not sure about is whether the 
> gain in readability of code compared to the existing ternary hacks is 
> enough to outweigh the increase in cognitive complexity of one more 
> language feature.

But it's not an increase - it's a decrease.  You get one form that is
both safe and IMO far more readable in place of at least three
different ugly, sometimes unsafe, hacks.  (three has to be a lower
bound, since we've seen at least one significant variation on all of
the above just in recent pre-308 discussion)




More information about the Python-list mailing list