I find it very easy to understand. In general, that should trump issues of speed, memory, or namespace.

Interesting justifiction. Personally, I prefer solutions that are:

  1. Clean.

    Don't create persistent, named temporaries to clutter, conflict and confuse the purpose of the code.

  2. Clear.

    Don't introduce unnecessary (and counterproductive) levels of indirection in the name of premature optimisation (avoiding copies).

    It is more expensive to takes references then dereference those references; than to make copies of simple, small scalar values:

    ($a,$b,$c,$d,$e) = 1 .. 5; cmpthese -1,{ a=>q[ my @a = ($a,$b,$c,$d,$e); ++$_ for @a;], b=>q[my @a = \($a,$b,$c,$d,$e); ++$$_ for @a; ] };; Rate b a b 525790/s -- -23% a 685872/s 30% --
  3. Concise.

    The goal of this snippet if to cross-compare a few variables with the only interest being a single boolean truth.

    Spreading that across half a dozen lines, adding named temporaries to the mix; adding a module, a callback and nested loops; and obscure indirections to derive a simple boolean does the very opposite of making things easy to understand.

  4. Simple.

    Simple means when the algorithm calls for:

    if( <some condition> ) { ## do somthing }

    the implementation (code) should reflect that. Not detract from the algorithm by introducing unneeded complexity.

  5. Efficient.

    looping to perform all 15 comparisons when the first or the second can resolve the boolean condition is just flagrant waste.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^4: Multiple Conditional Statements by BrowserUk
in thread Multiple Conditional Statements by jdlev

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.