Talk:Ternary conditional operator

message: What is the given argc argv example program good for? I don't understand what the
:ostream& sout = name ? fout : cout;
statement does. --Abdull 06:15, 28 March 2007 (UTC)
replies: text: It checks name to see if it is a null pointer. If it is, then it sets sout to a reference to cout (standard output), otherwise, it sets sout to a reference to the output stream fout. --Btx40 (talk) 19:53, 18 April 2008 (UTC)
thread_title:  argc argv example 

message: variable = condition and value_if_true or value_if_false
is incorrect: (true ? false : true) results as false; (true and false or true) results as true.
Jarod42 (talk) 13:32, 19 March 2012 (UTC)
thread_title:  Lua 

message: ===PHP?===
Is this the same as in PHP : $int = ($ifstatement) ? $thenvalue : $elsevalue;
: Yes.  See ?:. –EdC 23:00, 26 February 2007 (UTC)
replies: text: Added an example showing C code and referenced it. Xertoz (talk) 13:16, 1 December 2009 (UTC)
thread_title:  Sections from [[Talk:Ternary operation]] merged on July 2012 

message: Is this the same as in PHP : $int = ($ifstatement) ? $thenvalue : $elsevalue;
: Yes.  See ?:. –EdC 23:00, 26 February 2007 (UTC)
thread_title: PHP?

message: I see several other ternary operators, such as ?:, have articles, so I'm wondering if there's a name for this one or a category it falls under:
A Chinese language corpus I use (corpus here, documentation here, but they will only display properly in IE) has several ternary operators for searching, they basically do the same thing as regex but through operators such as $, +, -, etc. For instance, 中$5国 means "all results where 中 comes before 国 and they are separated by 5 or fewer characters"—so 中, 5, and 国 are its arguments. Does anyone know if there's a name for ternary operators like this? rʨanaɢ talk/contribs 23:35, 24 September 2009 (UTC)
thread_title:  Is there a name for this? 

message: There's little information about the ternary in C. Although the header references to the C syntax, there's no information on wether it's C99 etc and there is no example showing C code. Would someone with proper knowledge fix this? Xertoz (talk) 14:48, 23 October 2009 (UTC)
replies: text: Added an example showing C code and referenced it. Xertoz (talk) 13:16, 1 December 2009 (UTC)
thread_title:  C 

message: The C, C#, Java, and Javascript examples are completely 100% identical to each other. The Perl and PHP are also the same functionally, but just add the sigils those languages require. These excessive examples add absolutely nothing to helping understand what a ternary operation is. One example in a C-like language would be fine. 128.205.70.161 (talk) 18:23, 18 February 2010 (UTC)
thread_title:  Excessive examples? 

message: I understand the point but doesn't the use of only two things a and b fog the issue.
Shouldn't the distiction be something like X if Y else Z
or
if Y
result = X
else
Z.
The use of two variables a and b is also equivalent to asking for the max(a,b) if a language supported it. That is not the spirit of the topic. The spirit is if a>b there is a value returned and if not a different value. In fact the comparison used (a>b) confuses the issue as well. It should be a simple if true/false not necessarily a greater than. It need only be a boolean.  —Preceding unsigned comment added by 129.170.107.121 (talk) 21:19, 6 May 2010 (UTC)
thread_title:  a,b 

message: The article mentions 'Visual Basic', the link pointing to the 'Visual Basic.NET' article, and I'm not convinced that Visual Basic (_without_ .NET) has a higher version than 6, as of 2011.  — Preceding unsigned comment added by 89.132.149.210 (talk) 17:38, 4 November 2011 (UTC)
thread_title:  Is Visual Basic actually Visual Basic.NET here? 

message: Shouldn't be the page renamed “inline if operator” or so and list on it the various inline if's listed here.
The “?:” page would redirect to the language C item of the list.
I'm suggesting this because when I'm reading how to write inline if in python, it has nothing to do with the “?:” syntax.  Furthermore, I believe functional programming languages should be mentioned here, because in at least every functional programming language I've ever met, the conditional operators are “inline”.  For example in Haskell,
let x = if a == b then 17 else 84
is perfectly valid, even though it isn't written with an interrogation mark. Großinquisitor Zweihänder (talk) 17:10, 9 November 2012 (UTC)
replies: text: I think this is resolved by my move from ?: to Ternary conditional operator. Matma Rex talk 22:24, 1 November 2022 (UTC)
thread_title:  Rename page and include functional programming conditional expressions 

message: the example given for JS is currently:
var fooNotNull = (foo !== null) ? true : false;
var timeout = settings !== null ? settings.timeout : 1000;
Which is great if you already understand the ternary operator; you are able to figure out what the example is doing. If you don't it's cryptic. The example used on MSDN is much better and as follows:
var now = new Date();
var greeting = "Good" + ((now.getHours() > 17) ? " evening." : " day.");
Which it goes on to explain as:
var now = new Date();
var greeting = "Good";
if (now.getHours() > 17)
   greeting += " evening.";
else
   greeting += " day.";
Which is a million times better because even without knowing the ternary form you can see what is trying to be achieved. Obviously we can't lift MS's example but there must be many many more examples where the reader could understand the intention and therefore use it to understand the operator. such as 
var hemisphere = latitude >= 0 ? "northern" : "southern";
week day / weekend.
morning / afternoon.
anything where the test is intuitively obvious so we can learn the form by reading it. It may help if all the examples were the same.Flagpolewiki (talk) 15:51, 27 September 2014 (UTC)
replies: text: Well i'm going to go ahead and change this. Flagpolewiki (talk) 11:14, 13 December 2014 (UTC)
thread_title: Better Examples

message: For a noobie this article is not readable as it is to complicated! 
Whoever happens to navigate here does not know what :? operator is. Also that person have no clue to lots of other things in programming. An expert SE however have no reason to be looking for this stuff anyway. 
So mind the noobies and dont worry about the pros.  — Preceding unsigned comment added by AlphaOmega2211 (talk • contribs) 13:00, 25 December 2014 (UTC)
replies: text: I agree. It is only understandable by someone who already understands it. which is which i proposed using better examples. Flagpolewiki (talk) 09:46, 13 January 2015 (UTC)
thread_title: Overcomplicated

message: Wikipedia is not Rosetta Code. I think a list of "these languages have it", "these languages don't need a dedicated syntax for it", "these sort of have it" and "these don't" with some code samples where necessary would be useful, but this article is just a pile of "add your favorite language" and little actual substance.
And also ?:#Programming_languages_without_the_conditional_operator mentions Rust and CoffeScript, both of which are in the #Usage section as well. Akeosnhaoe (talk) 06:14, 6 April 2021 (UTC)
thread_title:  This article has too many code samples