Python-style ternary operator: a if pred else b
Arguments in favour:
- It does not have to be learned. A nonprogrammer can parse it.
- syntax highlighting will split
aandbvery nicely, as the keywords will be a different colour. - it reads naturally. (i.e. it conforms to our natural language). ‘Pythonic’.
Arguments against:
- people are familiar with
?: -
?:is fewer characters
My preference would be to have both available. When concision is paramount, use ?: otherwise use _ if _ else _.
-
pred ? a : bftw. -
a if pred else bwins, kill? - Allow both!
- MOO
0 voters