Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Ternary vs. Sort vs. Max

by sundialsvc4 (Abbot)
on Aug 10, 2015 at 23:16 UTC ( #1138089=note: print w/replies, xml ) Need Help??

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.

Replies are listed 'Best First'.
Re^2: Ternary vs. Sort vs. Max
by Your Mother (Bishop) on Aug 11, 2015 at 01:35 UTC

    Replied to the wrong post again. If I were a cop I'd be doing a field sobriety test on you at this point.

    Only one language with min/max, huh? Ever use SQL? I understand it's a bizarre, fringe language used by nearly no one but maybe you've heard of it.

    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1138089]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2020-01-25 20:53 GMT
Find Nodes?
    Voting Booth?