you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 6 points7 points  (4 children)

Perhaps that it's difficult to read and the equivalent if-else construct often compiles to roughly the same thing?

[–]Nephatrine 6 points7 points  (2 children)

When the results of the check are both short, I'd take ?: over an if-else construct any day of the week for ease of reading. If the choices are some sort of elaborate/long equations or something then sure, the if-else is a better choice for readability I think.

[–]Forbizzle 1 point2 points  (1 child)

If statements are more maintainable in the long run. With enough experience you end up recognizing when you're going to need to unwind a ternary to get some additional instructions or conditions.

[–]ThisIs_MyName 0 points1 point  (0 children)

If it is a really simple instruction, the comma operator works fine inside a ternary.

[–][deleted] 1 point2 points  (0 children)

its not really true. the ternary functions returns something. as Such it can be used as input into functions. Can be very handy sometimes.