organization:code_standards
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| organization:code_standards [2014/05/19 04:53] – created dmitriy | organization:code_standards [2015/12/11 05:36] (current) – dmitriy | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | 1) Format your code, please! | + | [[organization:: |
| - | 2) Use tabs for formatting, NOT SPACES. | + | [[how_to: |
| - | 3) Use ' instead of " for strings. | + | [[organization:: |
| - | 4) Comments go on the line ABOVE the code, NOT to the right of the code! | ||
| - | 5) General comments style is PHPDocumentor | ||
| - | Commented the start of page | + | === Стандарты === |
| + | - Use ' instead | ||
| + | - Don't use uninitialized variables. These errors can be avoided by using the built-in isset() function to check whether a variable has been set. | ||
| - | '' | ||
| - | /** | ||
| - | * Template processor class | ||
| - | * | ||
| - | * The template processor class allows keeping HTML code completely free of PHP code, but contain replacement fields. | ||
| - | * The class provides you with functions which can fill in the replacement fields with arbitrary strings. | ||
| - | * @package common | ||
| - | */ | ||
| - | '' | ||
| - | \\ Commented each function as it is defined in PHPDocumentor | ||
| - | |||
| - | There are also single commenting styles %%//%% applied where it is needed. | ||
| - | |||
| - | And… Do not document every bit of code in comments. | ||
| - | |||
| - | 7) Use switch statements where many elseif' | ||
| - | |||
| - | 8) ' | ||
| - | |||
| - | if ($var == ' | ||
| - | 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==' | ||
| - | |||
| - | All other styles should not to be used. This is it. Please use spaces before and after operators. | ||
| - | |||
| - | 9) ALL ' | ||
| - | |||
| - | '' | ||
| - | if ($a == b) | ||
| - | dosomething(); | ||
| - | '' | ||
| - | or: | ||
| - | '' | ||
| - | if ($a == b) dosomething(); | ||
| - | '' | ||
| - | They make the code more difficult to read and follow. | ||
| - | |||
| - | 10) class/ | ||
| - | '' | ||
| - | class testing | ||
| - | { | ||
| - | function print_to_screen() | ||
| - | { | ||
| - | global phpgw, phpgw_info; | ||
| - | |||
| - | if ($var == ' | ||
| - | 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(' | ||
| - | '' | ||
| - | |||
| - | 12) Use the long format for <? | ||
| - | |||
| - | 13) All code should start with no tab. Example: | ||
| - | |||
| - | <?php | ||
| - | dosomething(); | ||
| - | if ($a) { | ||
| - | dosomemorestuff(); | ||
| - | } | ||
| - | |||
| - | ?> | ||
| - | NOT: | ||
| - | <?php | ||
| - | dosomething(); | ||
| - | if ($a) { | ||
| - | dosomemorestuff(); | ||
| - | } | ||
| - | |||
| - | ?> | ||
| - | |||
| - | 14) Use stubbly-case (mixed-case) code. | ||
| - | |||
| - | Example: $currentUser is right, but $currentuser and $current_user are not. | ||
| - | Good function names are printLoginStatus(), | ||
| - | |||
| - | |||
| - | 15) Linefeeds: Ensure that your editor is saving files in the UNIX format. This means lines are terminated with a newline, not with a CR/LF combo as they are on Win32, or whatever the Mac uses. | ||
| - | |||
| - | 16) SQL code layout: Here's a sample of how ideally SQL code should look. Note where the lines break, the capitalization, | ||
| - | |||
| - | | ||
| - | |||
| - | |||
| - | SELECT field1 AS something, field2, field3 | ||
| - | FROM (table a, table b) | ||
| - | WHERE (this = that) AND (this2 = that2) | ||
| - | |||
| - | This is valid too however: | ||
| - | |||
| - | |||
| - | SELECT field1 AS something, field2, field3 FROM (table a, table b) WHERE (this = that) AND (this2 = that2) | ||
| - | |||
| - | ALWAYS enclose FROM tables into brackets – for LEFT JOIN compatability in MYSQL 5+. | ||
| - | |||
| - | SQL insert statements: SQL INSERT statements should be written LIKE UPDATE statemnets. | ||
| - | | ||
| - | |||
| - | |||
| - | # This is not what we want. | ||
| - | INSERT INTO mytable | ||
| - | VALUES (' | ||
| - | |||
| - | # This is correct. | ||
| - | INSERT INTO mytable SET column1=' | ||
| - | |||
| - | 17) Don't use uninitialized variables. These errors can be avoided by using the built-in isset() function to check whether a variable has been set. | ||
| - | |||
| - | | ||
| - | |||
| - | |||
| - | // wrong | ||
| - | if ($forum) ... | ||
| - | |||
| - | |||
| - | // correct | ||
| - | if (isset($forum)) ... | ||
| - | |||
| - | |||
| - | 18) Thanks for following these rules :) Please remember that those rules ARE STILL FLEXIBLE. If you work on existing code, you could vary your code styling to match existing code (if you think it makes sense). | ||
| - | |||
| - | |||
| - | Those rules are common for all non ZendFramework based projects. When the project is based on Zend Framework please follow Zend Framework code formatting!!! | ||
| - | |||
| - | |||
| - | [[organization:: | ||
organization/code_standards.1400475207.txt.gz · Last modified: (external edit)
