Ternary conditional operator: Difference between revisions

Content deleted Content added
m Result type: correct presumed typo
m ?: in style guidelines: Add note that appropriate use reduces the probability of buggy code vs. its less concise counterparts
Line 70:
Some corporate programming guidelines list the use of the ternary operator as bad practice because it can harm readability and long-term maintainability.{{Fact|date=November 2007}} However, when properly crafted the ternary operator is no more difficult to debug than the <code>if</code> statement equivalent (and in fact shouldn't require any debugging at all).{{Fact|date=November 2007}} Ternary operators are widely used and can be useful in certain circumstances to avoid the use of an <code>if</code> statement, either because the extra verbiage would be too lengthy or because the syntactic context does not permit a statement. For example:
 
[[C preprocessor|#define]] MAX(a, b) (((a)>(b)) ? (a) : (b))
 
or
Line 88:
feet;
</source>
This is much more readable and is more immediately recognized than thean equivalent <code>if/else</code> statementor equivalent<code>switch</code> construction, and such code is also more likely to be bug free and maintained correctly as the assigned variable is stated only once.
 
== Inconsistency of Implementations ==