Answer by Audrius Meškauskas for What are pros/cons of ternary conditional...
If statement duplicates the part specifying what to do with the conditionally selected value:if (condition) { use_value_now(alpha, beta, 0);} else { use_value_now(alpha, beta, 1);}It may be OK when the...
View ArticleAnswer by Alexander Goussas for What are pros/cons of ternary conditional...
Ternary operators are needed only in languages where if/else is not an expression. For example, in Java if/else is a statement so it cannot produce a value, thus the ternary operator. Contrast it with...
View ArticleAnswer by Ralf Kleberhoff for What are pros/cons of ternary conditional...
Recommendation:For expressions, provide the "same" set of conditional constructs that you provide for statements, and for readability, use similar syntax constructs.The ternary operator's semantics...
View ArticleAnswer by kaya3 for What are pros/cons of ternary conditional operators?
There is a very specific pitfall with ternary operators in statically typed languages which allow type coercions, like Java. Programmers like to refactor code like this to avoid...
View ArticleAnswer by Starship - On Strike for What are pros/cons of ternary conditional...
Pro:It’s more consiceThis pretty much speaks for itself. Makes life considerably easier and more optimized.
View ArticleAnswer by Rydwolf Programs for What are pros/cons of ternary conditional...
Pro: ReadabilityWhile plenty of people talk about the readability problems with misused ternary operators, there are also situations where using a full if/else would be annoyingly bulky, spreading a...
View ArticleAnswer by SK-logic for What are pros/cons of ternary conditional operators?
Pros:It's an expression, and in languages with distinction between expressions and statements it's crucial to have a selection operator available as an expression. Ternary operator is not necessarily...
View ArticleAnswer by Adám for What are pros/cons of ternary conditional operators?
Con: One more darned thing to rememberThe ternary syntax is very different from everything else, and requires somewhat complex additions to the precedence table.
View ArticleAnswer by FireTheLost for What are pros/cons of ternary conditional operators?
Con: Can lead to unreadable codeThe syntax of ?: is pretty unintuitive. Python's X if Y else Z is slightly better. However, this problem becomes worse if many such if-else expressions are nested. For...
View ArticleWhat are pros/cons of ternary conditional operators?
There are some languages that support ternary operator. There are Python, C, JavaScript, PHP.In languages like C and JavaScript, the syntax is like this:condition ? do_true : do_falsePython has another...
View Article