3 ms·
I find it interesting to see so much emphasis on small syntax nit-picking while totally forgetting the large scale question. Although I've used a ternary opera
by edejong 7y ago
I find it interesting to see so much emphasis on small syntax nit-picking while totally forgetting the large scale question.
Although I've used a ternary operator or 'if' statement from time to time, in general I would like to model the boundrary conditions themselves and separate condition and action (reduces coupling and enhances the possibility of reporting what is going on).
In your case, the a < b statement is most likely part of the natural ordering of the type of whatever variable a and b are. So we should be much more interested in describing the natural ordering of this type, so we can say things like:
intList.sort(IntOrdering.reverse())
to sort a list of ints in reverse order, or
intStringList.sort(IntOrdering.compose(StringOrdering))
to sort a list of tuples of ints and strings in natural ordering.
So, creating this natural ordering needs to be done only once, over all the possible programs that can be expressed with ints. Maybe that one, single, time you'd be writing the actual expression you wrote above. But this lower-level logic will be well hidden by the abstractions used to reason at a higher level about correctness when placed orthogonally with other low-level code.
In other words, every time I write ternary expressions or long if-then-else expressions, I am either writing something low-level, or I need to abstract away.