Re: Which is better coding style...

From: Date: Thu, 19 Apr 2001 20:35:43 +0000
Subject: Re: Which is better coding style...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-49417@lists.php.net to get a copy of this message
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" <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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net


« previous php.general (#49417) next »