NYCPHP Meetup

NYPHP.org

[nycphp-talk] structured programming in practice

csnyder chsnyder at gmail.com
Wed Jun 15 09:42:52 EDT 2005


On 6/14/05, Jayesh Sheth <jay_nyphp at fastmail.fm> wrote:

> I thought I would ask your opinions on using structured programming
> More specifically, what are your opinions on single points
> of entry and exit for functions?

I like the consistency of it, but I prefer code that is easy to read.
As long as the exits are well-marked, I say return wherever it makes
sense.

I typically bail out of functions or methods at the top if the
arguments don't validate, rather than create a big nested block.

As for figuring out why a function returned early... well, that's why
PHP needed exceptions, isn't it? Otherwise, I'm partial to using a
console to track those things...

$log = array();
function console( $message ) {
  global $log;
  $log[] = $message;
}

function make_beverage( &$bev ) {
  $aw = add_cwater( $bev );
  if ( ! $aw) {
    console( 'make_beverage: Unable to add water.' );
    return FALSE;
  }
  // ...
  return TRUE;
}

//...

// display console messages - developers only!
print '<pre>'.implode( "\n", $log ).'</pre>';



More information about the talk mailing list