summaryrefslogtreecommitdiff
path: root/posts/ternary-operators-revisited.mdwn
blob: ce422fd61b3d02ff79a067ba8cd8b131955ac37b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[[!meta title="Bang bang, you're dead…"]]
[[!meta author="Daniel Silverstone"]]
[[!meta date="2005-03-02 18:45:48 +0000"]]
[[!tag tech]]

Thanks to everyone who has commented about ternary operators. In
particular; thanks to Steve Alexander for pointing out [PEP
308](http://www.python.org/peps/pep-0308.html) to me along with [this
opinion](http://www.brunningonline.net/simon/blog/archives/000622.html)
that the python guys made the right choice.

Thanks also to the several people (namely Jonathon Jongsma, Matthew Good
and [Ross Burton](http://burtonini.com/) ) for either emailing me or
finding me on IRC to tell me about the fact that
`cond and truth or falsehood` is also a python idiom for the ternary
operator with the same caveats as the lua structure of the same form.
Gunnar Wolf made [a
posting](http://www.gwolf.org/index.php?gadget=blog&action=single_view&id=46)
about ternary operators too. Thanks for your comments there Gunnar;
interesting that perl6 will change the ternary operator from `? :` to
`?? ::`. I wonder how that will affect class/module members etc.

Unfortunately noone yet has come up with a nice plausible luaish idiom
for me to use in [Aranha](http://wiki.digital-scurf.org/Aranha) so I’m
going to have to continue to ponder them. The best I have so far is:
`(if cond then truth else falsehood)` where the parentheses are
obligatory.