4 ms·
Well, let me state this: John's version is not to my preference 'cause it has { in the same line as if, but I can live with that. But YOUR version uses not only
by sgift 14y ago
Well, let me state this: John's version is not to my preference 'cause it has { in the same line as if, but I can live with that. But YOUR version uses not only the ? operator, which should be burned with fire but it NESTS two of them together. Please, I want to die now. :(
Conclusion: We have different preferences.
- bagacrap 14y agonested ternaries are the same as if-else-if continuations. You figure that out one time, and it's easy to parse forever after. The ternary operator in general eases understanding because it extracts the common bit, i.e. "sides[i] =", meaning you don't have to carefully read the contents of each and every conditional block to verify nothing else is going on besides this one assignment.
- brooksbp 14y agothe ternary operator is awesome. it should be used more often.
- neutronicus 14y agoYeah, I really like it. It's a nice little oasis of Functional style in an otherwise pretty un-Functional language.
- barrkel 14y agoThe chained ?: idiom is very common in some C codebases. Having experienced it there, I find it highly readable, but it can sometimes benefit from parentheses to clarify precedence.
- zerooneinfinity 14y agoHow would you initialize a variable that depends on the truthfulness of another without the ternary operator. You should be careful when using extremes in programming.