Re: Which is better coding style...

From: Date: Thu, 19 Apr 2001 19:48:32 +0000
Subject: Re: Which is better coding style...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-49411@lists.php.net to get a copy of this message
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" <Chris.Boget@wild.net> To: "Php (E-mail)" <php-general@lists.php.net> 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 >

« previous php.general (#49411) next »