4 ms·
People definitely differ on the "easier to read" part. I find the 4 line if statement version more difficult to read in most cases. When things get long, my fav
by nickm12 9y ago
People definitely differ on the "easier to read" part. I find the 4 line if statement version more difficult to read in most cases. When things get long, my favorite formatting for a c-style ternary is:
my_variable = (my_very_long_condition)
? value_if_my_condition_is_true
: value_if_my_condition_is_false;
This is 3 lines, but there is almost no noise, just the condition and alternate values. Also, the variable is never assigned a dummy value (or left unassigned).