phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] phpgwapi/doc/coding_standard.txt, 1.8


From: nomail
Subject: [Phpgroupware-cvs] phpgwapi/doc/coding_standard.txt, 1.8
Date: Thu, 30 Dec 2004 07:47:26 +0100

Update of /phpgwapi/doc
Added Files:
        Branch: 
          coding_standard.txt

date: 2004/12/30 06:47:26;  author: skwashd;  state: Exp;  lines: +0 -0

Log Message:
new HEAD
=====================================================================
1) Format your code so that we can read it, please!

2) Use tabs for formatting, NOT SPACES.  Tabs create smaller files and editors 
allow
        developers to view a tab as however many spaces as they prefer.  Spaces 
do not allow this.
        There is one exception (see #11 below).

3) Use ' instead of " for strings.  This is a performance issue, and prevents
        a lot of inconsistent coding styles.

4) Comments go on the line ABOVE the code, NOT to the right of the code!

5) For each section of code put a section divider with basic explanation of the 
following
        code/functions.  It should look like this:

        
/****************************************************************************\
        * These functions are used to pick my nose                              
     *
        
\****************************************************************************/

6) Do not document every bit of code in comments.  PHP is an interpreted 
language and it will be
        nasty on performance.

7) Use switch statements where many elseif's are going to be used.  Switch is 
faster and I like it
        better!

8) 'If' statements need to use the following format:

        if ($var == 'example')
        {
                echo 'This is only an example';
        }
        else
        {
                echo 'This is not a test.  This is the real thing';
        }

        Do NOT make if statements like this:

        if ($var == 'example'){ echo 'An example'; }

        All other styles are not to be used.  This is it. Use it or I will 
personally come and nag you to
        death.

9) ALL 'if' statements MUST have matching { } (brackets).  Do NOT create 'if' 
statements like this:

        if ($a == b)
                dosomething();

        or:

        if ($a == b) dosomething();

        They make the code more difficult to read and follow.

10) class/function format:

        class testing 
        {
                function print_to_screen()
                {
                        global phpgw, phpgw_info;

                        if ($var == 'example')
                        {
                                echo 'This is only an example';
                        }
                        else
                        {
                                echo 'This is not a test.  This is the real 
thing';
                        }
                }
        }

11) Associative arrays must be written in the following manner:

        $array = array
        (
                'var'   => 'value',
                'var2'  => 'value2'
        );

        Note that tabs are preferred around the '=>'.

12) Use the long format for <?php.  Do NOT use <?.

13) All code should start with 1 tab.  Example:

<?php
        dosomething();
        if ($a)
        {
                dosomemorestuff();
        }

        NOT:

<?php
dosomething();
if ($a)
{
        dosomemorestuff();
}

14) Use lower case for variable and function names.  No stubbly-case 
(mixed-case) code.

15) Thanks for following these rules :)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]