I use these all the time. In my opinion, they make code more readable (so long as the person reading it knows what they are) and clarify the intent of what you are doing in many places.
Some places I like to use them include when the arguments to a method call are dependent on a condition:
Code:
wpiRelay.set(isOn
? edu.wpi.first.wpilibj.Relay.Value.kOn
: edu.wpi.first.wpilibj.Relay.Value.kOff);
when the return value of a function is dependent on a condition:
Code:
return isReversed
? !wpiSolenoid.get()
: wpiSolenoid.get();
when initializing a variable conditionally (you're almost required to use it here):
Code:
final double csd = isRedFriendly
? redScore - blueScore
: blueScore - redScore;
and in the middle of a complex statement I don't want to write twice just for the conditional (this one's from WPILib):
Code:
m_digitalOut |= ((value ? 1 : 0) << (channel - 1));
I try to follow the rule that a method should have only one return statement. One point of entry, one point of exit. Ternary operators make that much easier.