Definitely the second style :)

(If we were talking about C(++) then the first would have even been
forbidden by my companies coding standard as well as several coding
standards of other companies I worked for.)

The reason is this - a function has one entrypoint (duh) and one
exitpoint. Jumping out of a function somewhere in the middle leads to
unmaintainable code, and bugs when extending that function and that
return is overlooked. But, as with the indenting and bracket placing, it
is a matter of religion. They would have to torture me for three weeks
to get me to place the brackets like you did in your example :)


function blah() 
{
        $retval = "";

        switch( $bob ) 
        {
         case 1:
        $retval = "this";
        break;

        case 2:
        $retval = "that";
        break;

        default:
        $retval = "other";
        break;
        }
  
        return $retval;
}

> -----Original Message-----
> From: ..s.c.o.t.t.. [gts] [mailto:[EMAIL PROTECTED]] 
> Sent: 19 April 2001 21:31
> To: Php-General
> Subject: RE: [PHP] Which is better coding style...
> 
> 
> i say the first style.
> 
> unneeded variables and other thingies just
> obscure things and make it harder to maintain.
> 
> 
> > -----Original Message-----
> > From: Boget, Chris [mailto:[EMAIL PROTECTED]]
> > Subject: [PHP] Which is better coding style...
> > 
> > Which is better?
> > 
> > function blah() {
> >   switch( $bob ) {
> >     case 1:
> >        return "this";
> > 
> >     case 2:
> >       return "that";
> > 
> >     default:
> >       return "other";
> > 
> >   }
> > }
> > 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: 
> [EMAIL PROTECTED] To contact the list 
> administrators, e-mail: [EMAIL PROTECTED]
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to