@Soviut said:
@blakeyrat said:Whenever you have advice that sums to, "don't use it unless you're really careful," you're better off just not using it at all. If someone thinks it's ok to use it (for example, they see one you checked in), you know they'll abuse it the first chance they get.
I've seen enough unreadable disasters stemming from this that I'm firmly in the "never use it" group.
By that token, absolutely no programming feature should be used whatsoever, since they can _all_ be abused. It seems that most places that enforce really strict coding style tend to be lazy about doing code reviews. If your peers say "what does this mean?" or "I don't understand what you're doing here" then "clever" abuses don't make it into the code base.
You are missing the point - the ternary operator is not needed because it can be expressed using a simple if..else statement. It is also easy to abuse and hard to maintain (because as soon as the condition needs to be made more complex the statement becomes unreadable). For these reasons it is better not to use it.
@Soviut said:
A ternary, when used in the correct situations, winds up being far more readable than the long form if/else statements, especially when doing a lot of optional argument management at the beginning of a function/method. So by that same readability rule, observant peers would probably request a much leaner list of ternary statements than the long form.
I agree that a group of repeated ternary statements would be pretty clear, but I don't at all agree that it is easier to read than an if..else statement, and it is certainly not 'far more readable', unless you have problems reading if..else statements?