Re: Re: SHOULD I NOT USE "ELSE" IN IF STATEMENTS....?
| From: | O. Lavell | Date: | Mon, 08 Jun 2009 21:09:37 +0000 |
| Subject: | Re: Re: SHOULD I NOT USE "ELSE" IN IF STATEMENTS....? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-293770@lists.php.net to get a copy of this message | ||
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.