http://www.perlmonks.org?node_id=1138089


in reply to Ternary vs. Sort vs. Max

If “that’s the whole point of it,” as you say, then I can’t speak to that.   (And, mind you, I do not intend in any way to judge that.)   All that I can say is that I believe one should always look for the simplest, the most obvious, and of course the reasonably least-expensive way to do something.   “If what you are doing should require no thought, pretty-please don’t make me think about it.”

For instance, if you want to find the largest value in a list ... say, the largest card in your poker hand ... then you do not need to sort the list to find that out.   Your eyes can make a single furtive glance over your hand, and now you know.   Therefore, I would not ask the computer to perform any extra work for me, if it would not pay off otherwise.

As for the other two, ternary operators work really well in the place where (I think) they were intended:   when you want to make a simple, either/or choice in an arithmetic expression.   But, I always want to see my “glance rule” clearly upheld.   I want to always see, “at a glance,” exactly what I expect to see.

I like things like max() simply because they are nice and expressive.   They clearly say what is “the designer’s intent.”   In most languages they will do just the right thing, efficiently.

As an aside, I encountered one programming language ... HP/2000 Access BASIC ... which had a MAX/MIN operator.   It was so very expressive ... such a nice feature.