Amen! For both elimination of trailing {'s , and a good clear break.

I don't know how trailing {'s came about, but I find the blocks are harder 
to follow. I consider them HIDDEN rather than trailing, but I cut my teeth 
on Pascal, and FoxPro. While we're at it, how about plain old carriage 
returns to terminate the line and elimination of the ";"?

I still do a fair bit of work in Visual FoxPro, where the semi-colon 
indicates line continuation. Some days I introduce strange bugs when 
switching from PHP to VFP, and vice versa.

Miles

At 01:48 PM 4/19/01 -0600, Steve Lawson wrote:
>Personally, I hate trailing {'s
>
>I think this
>
>function blah()
>{
>    switch( $bob )
>    {
>       case 1:
>          $var = "whatever";
>       break;
>    }
>}
>
>Is much easier to read and follow.  As for the exiting question...
>
>The "proper" way is to use the breaks.  "They" say that multiple returns in
>any function = bad programming.  The .0001 second that it takes to break and
>return the value will never matter.
>
>Plus, you or someone else may have to add to that function later.  Let's say
>I wanted to add "</B>" to the end of $retval.  If you use the normal way I
>can just make one change, return $retval . "</B>"; instead of changing 3
>different returns.
>
>SL.
>
>
>
>----- Original Message -----
>From: "Boget, Chris" <[EMAIL PROTECTED]>
>To: "Php (E-mail)" <[EMAIL PROTECTED]>
>Sent: Thursday, April 19, 2001 11:57 AM
>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";
> >
> >   }
> > }
> >
> > function blah() {
> >   $retval = "";
> >
> >   switch( $bob ) {
> >     case 1:
> >        $retval = "this";
> >        break;
> >
> >     case 2:
> >       $retval = "that";
> >        break;
> >
> >     default:
> >       $retval = "other";
> >        break;
> >
> >   }
> >
> >   return $retval;
> >
> > }
> >
> >
> > In other words, is it good practice to exit out of a block (any
> > block... not just switch; if, for, while) prematurely as demon-
> > strated in the first example?  Or should you do it as demon-
> > strated in the second example?
> >
> > Chris
> >
>
>
>--
>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