3 ms·
I never really understood the distaste for it, or how it’s non-obvious. It seems like the people I’ve talked to object to the punctuation-based syntax more than
by evincarofautumn 9y ago
I never really understood the distaste for it, or how it’s non-obvious. It seems like the people I’ve talked to object to the punctuation-based syntax more than the semantics, because it exactly mirrors conditional statements, even when nested. (Well, except in PHP, but that’s a bug in the grammar.)
if (a) { b } else if (c) { d } else { e }
a ? b : c ? d : e
if (a) { b } else { if (c) { d } else { e } }
a ? b : ( c ? d : e )
The question mark goes after the thing you’re asking about, like in English. The colon to separate the true and false branches is totally arbitrary, I grant you. I’d prefer to have the if…else notation available as an expression, but the statement-expression distinction hasn’t quite died yet.
Personally, I don’t care for Python’s version with the condition and true branch swapped, because I read it like invalid Forth, expecting “condition IF true-branch ELSE false-branch THEN”. :P