Normally referring to the conditional operator, represented by the characters ? and :, that form a basic conditional expression in several programming languages, also known as inline if. It is used as follows: (condition) ? (value if true) : (value if false).
5
votes
2answers
195 views
Concise nested statements
I really like the ruby ? : syntax for if else statements.
However, I'm not sure how to do the following with a nested ...
7
votes
3answers
423 views
Ternary extension method
I created the following HtmlHelper extension method for my Asp.Net MVC Razor views because the ternary syntax sucks when you need to use it intermixed with markup.
Is there a better way to write this ...
11
votes
3answers
894 views
Reduce code complexity by applying ternary operator
I have a condition in my code where I need to put a lot of nested else if statements. However, I have managed to reduce some if ...
7
votes
2answers
203 views
Reasonable use of the comma operator?
I've just posted this solution in my review of @adrienlucca's question, which is to read three rows of six tab-separated doubles.
...
4
votes
3answers
137 views
Execute method on ternary operator result?
I have two List<T>s of the same T and a T object. Based on a condition, I want to add ...
2
votes
1answer
63 views
Property getter implementation
I always see something like this:
- (NSMutableArray*)items {
if (_items == nil)
_items = [NSMutableArray array];
return _items;
}
Recently I ...
2
votes
1answer
604 views
Python - Strip whitespace from strings in list that contains elements of various types
Let's say I have a list that contains strings and integers. The strings can contain leading and trailing whitespace that I'd like to remove. I can't just strip() ...
3
votes
2answers
129 views
An abundance of ternary operators
I'd like to find a way to do what this method does in a cleaner, less hacky looking way
...
8
votes
4answers
375 views
3
votes
2answers
496 views
Shorthand if conditional in php
(!empty($student->former_name) ? print $student->former_name : '');
I only want to print out the former name if it is not empty, nothing else.
I imagine I ...
3
votes
2answers
771 views
Ternary Operator, check if Datetime is MinValue and set value to it. There is a elegant way to do it?
There is a better or more elegant way to do this ?
ctroRegistro.DataHoraCriacao is Datetime.
...
34
votes
4answers
4k views
Ternary operation in Java - isn't this abuse?
I think the below code is difficult to understand. I also feel it abuses Java's ternary operator.
...
8
votes
4answers
450 views
Ternary operator and comments
I have a class that spawns threads to process data. I am working on instrumentation code. When the process is started, time = System.currentTimeMillis(); When it ...
26
votes
3answers
3k views
Cleaner usage of the ternary “?” operator
I've recently been doing some mods to some old code I've been maintaining for a couple of years now.
As part of a wider set of scripts using YAHOO YUI 2.2 (yes, that old) for dialog-style panels, I ...