Ternary operator

I, for one, emphatically throw my hat into the ring AGAINST the standard C-style ternary operator

And this is definitely unnecessary functionality with if-else expressions.

The phrase you are looking for is “easier to read”.

ternary operator is the most lopsided operator there is because it is a postfix on the condition. Imagine reading from right to left, x = a, ok a gets assigned to x, now ?, WTF? x = a ? b, WTF?, x = a ? b :, Huh?. Compare that to x = if, OK at this point I know x is getting assigned the result of a conditional.

The phrase you are looking for there is “hard to read” or “unobvious”. And they will likely have to repeatedly look it up.

They see that and they already know what an if-else is. Only difference is that it has a value instead of continuing the artificial Java and C limitation that if has no value. Lots of other languages already have if-expressions and this is easy for them to read. I think a non-programmer could figure out what x = if(a) b else c means.

Certainly no one is talking about removing conditional expressions. Ternary operator exists ONLY because in C if was a statement not an expression. With that limitation gone ternary operator has no reason to exist.

1 Like