It’s called a ternary conditional operator and I would say a) not to use it in general, and b) if you must, keep it REALLY simple, like this:
a = b ? c : d;
or MAYBE, just maybe:
a = b < K : c : d
In a code review I would reject the code that Mr Miller posted above because:
- it is infinitely easier to inadvertently introduce a bug
- it is infinitely harder to reason about at a glance
- it is infinitely harder to test exhaustively
- it’s not fooling the compiler: the code will not be faster
- nobody pays you to save code lines… we have
#region
s we can fold if need be - writing code like that is NOT actually being clever or better
- it will make me MUCH more suspicious of all other code by an engineer who does this a lot
Break it up, practice social distancing in your code, one thing per line please.
“Programming is hard enough without making it harder for ourselves.” - angrypenguin on Unity3D forums
“Combining a bunch of stuff into one line always feels satisfying, but it’s always a PITA to debug.” - StarManta on the Unity3D forums