Defending the ternary operator
Andrew Koenig
ark at research.att.com
Sun Feb 9 23:53:25 EST 2003
Martin> 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.
Martin> Better yet, it would save otherwise kind and compassionate
Martin> people from having to foist these wretches off on the innocent
Martin> who come to them for assistance.
LOL!!
>> 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.
Martin> But it's not an increase - it's a decrease. You get one form
Martin> that is both safe and IMO far more readable in place of at
Martin> least three different ugly, sometimes unsafe, hacks. (three
Martin> has to be a lower bound, since we've seen at least one
Martin> significant variation on all of the above just in recent
Martin> pre-308 discussion)
+1.
--
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark
More information about the Python-list
mailing list