Subscribe:

September 25, 2006

Code Style

Filed under: — Scott @ 11:50 pm

Running notes on my coding style. The older the script the more likely I didn’t use a guideline:

  1. I always test for a positive value. This means that when I am testing for a condition and I never use the “inverse of” operator.
    What I avoid:
    if( ! $varname)
    {
    # then do something
    }

    What I do:
    if( $varname)
    {
    #     then  do nothing
    } else {
    #     then  do something
    }
    

    I believe this make for easier reading for less experienced programers.

  2. class and object names are prefaced with lower case c or o respectively and use the camel notation.

    What I do:
    class cClass {
         function __construct()
       {
       }
    }
    
    $oMyClass = new cClass();
    

  3. Variables that are not objects use underscore notation.

    What I do:
    $counter_for_loop = 1;
    

Popularity: 1% [?]

Digg!

RSS feed

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.