I fall in the camp that nested ternaries are bad and should be refactored to make more sense to the casual reader so setting breakpoints on indented ternaries will never be in my code.
I find use cases for ternaries exceedingly rare. I only use them in trivial cases, like:
var foo = (useA) ? a : b;
Even then, I'm a lot more likely to do:
var foo = b;
if (use A) {
foo = a;
}
Pretty much only really use them when the case is trivial and there's an aesthetic benefit to keeping the whole assignment on one line (e.g. it's just one in a long list of things being assigned).
4
u/tipdbmp Mar 27 '15
It's easier to debug (you can set breakpoints) when if/else-if/else statements are being used.
But if you insist on using nested ternary operators, then in my opinion it's better to format them in a table:
Note that in both cases the "good" outcome goes last and it's preceded by all the "error" checking (that's generally a good advice).