in reply to Re^3: Conditional Elimination
in thread Conditional Elimination

I'd say that correctness is far more important than speed when it comes to assigning order.
But the most important thing is to put the condition in a sub so that it's easier to understand.
How does that magic work? You're still have the same tests. Personally, I find:
if (bunch of clauses) { code }
easier to understand then
if (pointer-where-to-find-clauses) { code }
specially when it comes to better understanding of the clauses.

Replies are listed 'Best First'.
Re^5: Conditional Elimination
by dsheroh (Monsignor) on Aug 31, 2011 at 09:03 UTC
    The magic works by assigning a name to the operation - names are very powerful magic.

    Personally, I find:

    if ($zipcode == 12345 || $zipcode == 55344 || $zipcode == ...) { code }
    much harder to understand than
    if (is_valid_zipcode($zipcode)) { code }
    specially when it comes to better understanding of what the code is meant to accomplish.
      Hmmm, the former clearer says to me "ah, he's checking whether the zip code is one of a given list", while the latter tells me he's validating a zipcode. I'd would find it surprising if is_valid_zipcode(10012) returns false, while it doesn't surprise me in your first snippet.

      Names are so much easier to get wrong, or be ambiguous.

        Names are so much easier to get wrong, or be ambiguous.

        Yes, getting programmers to use meaningful names rather than the first that pops into their head is a problem.

Re^5: Conditional Elimination
by shawnhcorey (Friar) on Aug 31, 2011 at 14:21 UTC

    The magic works for the same reason you would break a long sequence of statements in subroutines.