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

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.

Replies are listed 'Best First'.
Re^6: Conditional Elimination
by JavaFan (Canon) on Aug 31, 2011 at 12:13 UTC
    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.