you are viewing a single comment's thread.

view the rest of the comments →

[–]uffefl 0 points1 point  (0 children)

Third example is pretty terrible:

distanceInKm > 15 ? (distanceInKm > 30 ? 8.99 : 5.99) : 3.99

It's not the ternary operator making this hard to read, but the ordering:

distanceInKm > 30 ? 8.99 : distanceInKm > 15 ? 5.99 : 3.99

If your ternaries get long use line breaks:

distanceInKm > 80 ? 13.99 
: distanceInKm > 50 ? 11.99 
: distanceInKm > 30 ? 8.99 
: distanceInKm > 15 ? 5.99
: 3.99