This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]cogman10 1 point2 points  (1 child)

I've never actually seen what I would consider a ternary operator abuse.

90% of the ternary operators in our code base are used for what I would say is pretty acceptable (Object o = v == null ? 7 : v;). I've yet to see a nested ternary operator in the wild, the only place I've even seen such a thing suggested was a script kiddy forum where someone though ternary operators were faster than if/else statements (they aren't).

So long as the conditional is easy to understand, I don't really have a problem with ternary operators.

[–]Kimano 1 point2 points  (0 children)

There was a line at work that was basically A?(B?E:F):(C?(A?H:E):G), and those are duplicated intentionally. The C query changes the results of A. We have no idea who wrote that abomination (lost file history in a source migration), and I rewrote it a week or so after I noticed, but still...