source: trunk/phpgwapi/doc/coding_standard.txt @ 2

Revision 2, 3.4 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
11) Format your code so that we can read it, please!
2
32) Use tabs for formatting, NOT SPACES.  Tabs create smaller files and editors allow
4        developers to view a tab as however many spaces as they prefer.  Spaces do not allow this.
5        There is one exception (see #11 below).
6
73) Use ' instead of " for strings.  This is a performance issue, and prevents
8        a lot of inconsistent coding styles.
9
104) Comments go on the line ABOVE the code, NOT to the right of the code!
11
125) For each section of code put a section divider with basic explanation of the following
13        code/functions.  It should look like this:
14
15        /****************************************************************************\
16        * These functions are used to pick my nose                                   *
17        \****************************************************************************/
18
196) Do not document every bit of code in comments.  PHP is an interpreted language and it will be
20        nasty on performance.
21
227) Use switch statements where many elseif's are going to be used.  Switch is faster and I like it
23        better!
24
258) 'If' statements need to use the following format:
26
27        if ($var == 'example')
28        {
29                echo 'This is only an example';
30        }
31        else
32        {
33                echo 'This is not a test.  This is the real thing';
34        }
35
36        Do NOT make if statements like this:
37
38        if ($var == 'example'){ echo 'An example'; }
39
40        All other styles are not to be used.  This is it. Use it or I will personally come and nag you to
41        death.
42
439) ALL 'if' statements MUST have matching { } (brackets).  Do NOT create 'if' statements like this:
44
45        if ($a == b)
46                dosomething();
47
48        or:
49
50        if ($a == b) dosomething();
51
52        They make the code more difficult to read and follow.
53
5410) class/function format:
55
56        class testing
57        {
58                function print_to_screen()
59                {
60                        if($var == 'example')
61                        {
62                                echo 'This is only an example';
63                        }
64                        else
65                        {
66                                echo 'This is not a test.  This is the real thing';
67                        }
68                }
69        }
70
7111) Associative arrays must be written in the following manner:
72
73        $array = array(
74                'var'  => 'value',
75                'var2' => 'value2'
76        );
77
78        OR:
79
80        $array = array
81        (
82                'var'  => 'value',
83                'var2' => 'value2'
84        );
85
86        Note that spaces are preferred around the '=>'.  This is because only tabs
87        on the left side are guaranteed to line up correctly using different
88        tabstops.
89
9012) Use the long format for <?php.  Do NOT use <?.
91
9213) All code should start with 1 tab.  Example:
93
94<?php
95        dosomething();
96        if ($a)
97        {
98                dosomemorestuff();
99        }
100
101        NOT:
102
103<?php
104dosomething();
105if ($a)
106{
107        dosomemorestuff();
108}
109
11014) Use lower case for variable and function names.  No stubbly-case (mixed-case) code.
111
11215) (int)$var is preferred vs. intval($var).  Also, is_int()/is_string()/is_array()
113  should be used instead of gettype() where possible.
114
11516) str_ functions should be used instead of ereg_ for simple text replacement, etc.
116  For example, ereg_replace(';','',$string) is much slower than str_replace(';','',$string.
117  Of course, for complicated regular expressions, you may still need ereg_.
118
11917) Use the api function, copyobj($oldobject,$newobject), instead of
120  $newobject = $oldobject.  This is for performance when using php5.
121
12218) Try to avoid creating new objects when the api-created ones will work.
123  This is a performance issue.  You might also be able to use copyobj() and then
124  call the constructor of the class if another version of the object exists
125  already.
126
12719) Do not use, e.g., global $var; unless absolutely necessary.  Please
128consider developing with register_globals=off to understand why.
129
13020) Thanks for following these rules :)
Note: See TracBrowser for help on using the repository browser.