in reply to if else and not reachable coding style

My tendency is to the first construct when COND is true or false based on an option contained in the argument list and the third when COND is true or false based on improper inputs, e.g., such as log(0) or on external factors (the network is down).

I find the second case unesthetic, as the die statement is, at best, superfluous. Indeed, I would not be surprised if Perl optimized it away.

emc

" When in doubt, use brute force." — Ken Thompson
  • Comment on Re: if else and not reachable coding style

Replies are listed 'Best First'.
Re^2: if else and not reachable coding style
by Anonymous Monk on Mar 08, 2006 at 21:20 UTC
    I assumed the second case was really supposed to be more like this:
    if ( CASE1) { return 1; } elsif ( CASE2 ) { return 2; } else { die("Must be one of CASE1 or CASE2"); }

    That is, a case where formal logic without knowledge of the inputs can't tell you what the results will be, but the business rules demand that the result be one of two choices.

    It's always good to have an exception handler for when things that other people swear will never, ever happen suddenly do happen anyway. ;-)

    --
    Ytrew