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).

learn more… | top users | synonyms

2
votes
1answer
50 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() all elements because some are ...
3
votes
2answers
108 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 def self.create_from_person!(person) spi = new(:person => person, :provider => person.provider) ...
2
votes
2answers
101 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 do not need the else part of it, but ...
29
votes
7answers
3k views

Is using the ternary operator like this considered less readable?

I often like to do things like this: return (aCondition == aThing) ? someLongExpression.getAThing() : somethingElse; Is this practice considered more or less readable than using a ...
3
votes
2answers
348 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. ctroRegistro.DataHoraCriacao = ctroRegistro.DataHoraCriacao == DateTime.MinValue ? ...
21
votes
8answers
1k views

Is it bad to use a ternary inside of an if condition?

Let's suppose I have some sort of form that automatically performs a copy procedure when the user either focuses on a textbox, or highlights some text. Let's suppose that the user has a preference of ...
22
votes
4answers
2k views

Ternary operation in Java - Isn't this abuse?

I think that below code makes it difficult to understand and also I feel it's abuse of ternary operator in Java. Code snippet: String name = ...
6
votes
4answers
421 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 completes, time = ...
17
votes
3answers
2k 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 ...