in reply to Re: Conditional Elimination
in thread Conditional Elimination

Your speed argument doesn't make any sense. Really, you think calling a sub and hand rolling your own short circuiting beats the build in short circuiting of && and ||?

Replies are listed 'Best First'.
Re^3: Conditional Elimination
by shawnhcorey (Friar) on Aug 30, 2011 at 22:56 UTC

    No, I think using a sub makes it easier to read. Making those tests that will return early will not slow it down as much as putting them in random order. It's just something to keep in mind when writing the sub. But the most important thing is to put the condition in a sub so that it's easier to understand.

      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.
        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.

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