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}";

_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

Reply via email to