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

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

 



It's for better code.

Personally, I'm trying to get away from multiple return/exit paths,
and practice more OOC/Eiffel-like coding (I haven't sprung for the
book Object Oriented Construction yet
http://archive.eiffel.com/doc/oosc/page.html ) and I'm not quite
taking advantage of Design By Contract in my Eiffel coding yet though
either.

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.
}

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.

-- 
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