Hacker News new | comments | show | ask | jobs | submit login

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.

nested 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.

The 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.

How 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.

the ternary operator is awesome. it should be used more often.

Yeah, I really like it.

It's a nice little oasis of Functional style in an otherwise pretty un-Functional language.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact