by Pxtl · 5y ago · 0 comments
So many languages use clear words like "if" and "then" and "else" and parens and curly braces for conditional statements...
But then they go full Perl and mash their faces against the keyboard when developing syntax for conditional expressions.
It's bone-headed language-design that C did wrong and everybody else continues to do wrong because C.
myvar = condition_1 ? value_1
: condition_2 ? value_2
: condition_3 ? value_3
: value_fallback;Under what circumstances would that happen? I've never encountered a nested ternary that wouldn't be better replaced with readable code, so now I'm wondering what experiences I've been missing. :)
myvar = if(condition_1) {value_1}
else if(condition_2) {value_2}
else if(condition_3) {value_3}
else {value_fallback}; #define TERN(c, a, b) c ? a : b
I'm not a fan of ternaries, but that macro makes it kind of more ligible. #define TERN(c, a, b) ((c) ? (a) : (b))As Liquid_Fire points out, it's also probably incorrect.