I like the ternary. Like @fnh
pointed out, it's the only way of doing direct conditional assignment in most languages. And for the most part, we've conditioned ourselves to how it works.
But I have a hard rule: never nest a ternary. No matter how clever it makes me seem, or how many articles I read on functional programming and why ternaries are awesome, I won't. The stress it puts other programmers (and myself!) through to mentally parse a nested ternary isn't worth it.
Yes, nesting of the second argument, the truth value, can be hideous. Nesting, or better called chaining, of the third argument can be acceptable with good formatting.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I like the ternary. Like @fnh pointed out, it's the only way of doing direct conditional assignment in most languages. And for the most part, we've conditioned ourselves to how it works.
But I have a hard rule: never nest a ternary. No matter how clever it makes me seem, or how many articles I read on functional programming and why ternaries are awesome, I won't. The stress it puts other programmers (and myself!) through to mentally parse a nested ternary isn't worth it.
Yes, nesting of the second argument, the truth value, can be hideous. Nesting, or better called chaining, of the third argument can be acceptable with good formatting.