Ternary conditional operator: Difference between revisions

Content deleted Content added
m {{unreferenced|article|{{subst:DATE}}}}
SmackBot (talk | contribs)
m Date/fix the maintenance tags or gen fixes using AWB
Line 1:
{{unreferenced|articleUnreferenced|date=November 2007}}
'''<code>?:</code>''' is a [[ternary operator]] that is part of the syntax for a basic [[conditional statement|conditional expression]] in several [[programming language]]s including [[C (programming language)|C]], [[Objective-C]], [[C++]], [[C Sharp|C#]], [[D programming language|D]], [[Java (programming language)|Java]], [[JavaScript]], [[Linoleum programming language|Linoleum]], [[Perl]], [[PHP]], [[Tcl]], [[Ruby programming language|Ruby]], and [[Verilog]].
 
Line 65:
 
===?: in style guidelines===
Some corporate programming guidelines list the use of the ternary operator as bad practice because it can harm readability and long-term maintainability.{{factFact|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).{{factFact|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))