NYCPHP Meetup

NYPHP.org

[nycphp-talk] All In the Game of PHP

Paul Houle paul at devonianfarm.com
Wed Jun 13 21:29:32 EDT 2007


Peter Sawczynec wrote:
> The number one muck up I have observed in coding, is programmers
> creating functions or tools that leave off the final "else" clause at
> the 
> end of a conditional logic tree. That is, programming logic error
> examples, such as:  
>   
    Long if-then-else ladders are an antipattern.  After a while,  they 
usually end up like this list:

http://www.multicians.org/thvv/borges-animals.html

    In some cases,  switch/case is better:

http://www.php.net/manual/en/control-structures.switch.php

    Other good patterns are 'guarded method/subroutine'

function a_good_subroutine($x) {
    if (invalid_input($x)) {
       return;
    }

    ... do something ...
}


    and the patterns of 'computed subroutine name',  'computed method 
name',  'computed object name' and 'computed file name';  ie.

if (invalid_type($data_type)) {
    throw new Exception("...");
}

require "something-doers/do-something-to-{$data_type}";




More information about the talk mailing list