Re: Re: SHOULD I NOT USE "ELSE" IN IF STATEMENTS....?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dee Ayy wrote:

> It's for better code.
> 
> Personally, I'm trying to get away from multiple return/exit paths,

Hurray for you :)

[..]

> At a minimum, I would change this:
> 
> function doThisAndThat($bTrueOrFalse) {
>     if ($bTrueOrFalse)
>     {
>         return 'It is true';
>     }
> 
>     /* If the above is true we can be sure it's NOT true here. */ return
>     'It is false';
> }
> 
> to this:
> 
> function doThisAndThat($bTrueOrFalse) {
>    $return_value = 'It is false';   // Set your default state here.
>     if ($bTrueOrFalse)
>     {
>         $return_value = 'It is true';  //  Update state.
>     }
> 
>     return $return_value; // Only 1 exit path.
> }

Yes. This is also perfectly compatible with the diagramming method I 
mentioned previously.

> I've also noticed that, for the most part, PHP itself codes
> functions_or_variables_like_this, while coming from Java, my PHP code
> looksLikeThis.
> 
> Slightly more readable for say do_www_design versus doWWWDesign versus
> do_wwwd_esign for those times when you run into such names.

It shouldn't matter much which style you use, as long as you are 
reasonably consistent in it.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux