Ternary operators
Daniel Silverstone asks about ternary operators, and whether people like to use them.
Well, I know I do. In fact, it's the single operator I like to use a lot. Too much, in fact -- sometimes I abuse it in horrible ways, such as nesting the thing three times, or so. Which is stuff that gets removed after a first reading, of course.
Most of the Microsoft languages have IIF, a function that does basically the same thing (as in "iif(condition, trueval, falseval)"). I find that a bit more intuitive than the ?: construct, but the difference isn't that important since it's semantically the same thing (and, more importantly, the ?: operator requires less characters, so is nicer).
I'm not sure about most other languages. I have learned a lot of programming languages at school, but it's been way too long, and I don't use most of them anymore. I'm quite positive that COBOL does not support it, so you need to type it out in a full 'if' structure. But that's okay, because writing COBOL feels like writing a novel anyway.
Python doesn't have it but there are work arounds(ugly and semi-broken). However, it can get complicated.
[false_exp, true_exp][condition]
isn't real ternary as both condition would be evaluated before the condition.
condition and true_exp or false_exp
is sort of except that if true_exp is also evaluate to false, false_exp will be evaluated and return, again it sucks.
To implement ternary in python, it needs to be something like :
[curried_false_exp, curried_true_exp]condition
This defer the evaluation after the condition.
Well it will have a formal on in 2.5