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
a
andb
very 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 : b
ftw. -
a if pred else b
wins, kill?
- Allow both!
- MOO
0 voters