On Sun, 2002-02-17 at 11:05, Christian Blichmann wrote:
> Hi there!

[snip]

>             if (condition) one_statement();
> 
>             if (condition)
>                 one_statement();
>             else
>                 other_statement();
> 
>             if (condition)
>                 one_statement();
>             elseif (condition)         // or use: else if
>                 other_statement();
>             else
>                 anything();

I don't see the benefit of leaving the braces out when there is only
one statement, and there is potential harm: it's fairly easy to get 
hard-to-track errors when you add more statements to the conditional
but forget to add braces (which might as well have been there to
start with):

if (contition)
    $foo = 'bar';
    echo $foo
else
    baz();

I've seen it happen. :) Besides, if code block are always braced, it's
one less inconsistency in the code.

[snip]

One other thing I'd mention is when people go to great lengths to format
columns in their code:

$foo    = 'Foo';
$bar    = 'Bar';
$foobar = 'FooBar';
 
This is a small example, but despite the fact that it's sort of  
aesthetically pleasing, what happens when you have a long list of 
those and then come back and need to add one which is one character
longer than the rest? You have to update *every* line. Not a code
problem per se, but a tedious mess.

An excellent book on coding practices is 'Code Complete', by Steve C
McConnell.
 
http://www.amazon.com/exec/obidos/ASIN/1556154844/qid=1013978113/sr=8-1/ref=sr_8_67_1/102-2030399-6728144

There is also the Indian Hill style guide--for C, but highly 
transferrable to PHP:

http://dogbert.comsc.ucok.edu/~mccann/cstyle.html

For a whole list of 'em, check out:

http://www.cs.umd.edu/users/cml/cstyle/


Hope this helps,

Torben

-- 
 Torben Wilson <[EMAIL PROTECTED]>
 http://www.thebuttlesschaps.com
 http://www.hybrid17.com
 http://www.inflatableeye.com
 +1.604.709.0506


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

Reply via email to