Development

CodingStandards (diff)

You must first sign up to be able to contribute.

Changes between Version 11 and Version 12 of CodingStandards

Show
Ignore:
Author:
nicolas (IP: 82.226.137.29)
Timestamp:
05/20/08 22:37:32 (9 years ago)
Comment:

Moved content

Legend:

Unmodified
Added
Removed
Modified
  • CodingStandards

    v11 v12  
    1 Developers who contribute to the project should follow a few guidelines. 
    2  
    3 = Commits = 
    4  
    5 Some contributors have a commit right to the symfony repository. In this case, they work in an forked branch of the code, and the merge is done by the core team before major releases. 
    6  
    7  * Always do granular commits, each related to a specific feature. Don't mix unrelated modifications in a commit, so that debugging (and reverting) can be easier. 
    8  * Use a descriptive label for your commit, with verbs in past tense. All the developers should understand what it does and why, and it should be short. 
    9  * Always provide the unit tests to validate the code you commit. 
    10  * Always document the functions and methods you add or modify (using phpdoc) 
    11  * For commits to a branch, prefix the commit message with the branch name. For example: "fabien: fixed trouble." 
    12  * If your commit closes a ticket in the bug tracker, suffix your commit message with the text "(closes #1234)", where "1234" is the number of the ticket your commit fixes. 
    13  * If you commit someone else code, suffix your commit message with the text "(patch from abc)", where abc is the trac login of the patch writer. 
    14  
    15 = Coding practices = 
    16  
    17  The golden rule: '''Imitate the existing symfony code''' 
    18  
    19  * Never use tabulations in the code. Indentation is done by steps of 2 blanks. 
    20  * Don't put spaces after an opening parenthesis and before a closing one. 
    21   {{{ 
    22  if ($reqvalue == _getRequestValue($name))    correct 
    23  if ( $reqvalue == _getRequestValue($name) )  incorrect 
    24   }}} 
    25  * Use camelCase, not underscores, for variable, function and method names. 
    26  * Use underscores for helper functions name (only for symfony 1.0 stuff). 
    27  * Use underscores for option/argument/parameter names. 
    28  * Braces always go on their own line. 
    29  * Use braces for indicating control structure body regardless of number of statements it contains. 
    30  * Don't end library files with the usual ?> closing tag. This is because it is not really needed, and because it can create problems in the output if you ever have white space after this tag. 
    31  * In a function body, return statements should have a blank line prior to it to increase readability. 
    32 {{{ 
    33 function fooFunction() 
    34 
    35   if (condition2 || condition3) 
    36   { 
    37     statement1; 
    38     statement2; 
    39  
    40     return 1; 
    41   } 
    42   else 
    43   { 
    44     defaultaction; 
    45   } 
    46  
    47   return null; 
    48 
    49 }}} 
    50  * All one line comments should be on their own lines and in this format. 
    51    {{{  
    52   // space first, with no full stop needed 
    53    }}} 
    54  * Avoid evaluating variables within strings, instead opt for concatenation 
    55    {{{ 
    56    $string = 'something'; 
    57    $newString = "$string is awesome!";    // bad, not awesome 
    58    $newString = $string.' is awesome!';   // better 
    59    $newString = sprintf('%s is awesome', $string); // for exception messages and string with a lot of substitution 
    60    }}} 
    61  * Use lowercase constants: false, true, null 
    62  * To check if a variable is null or not, use the is_null() function 
    63  * When comparing a variable to a string, put the string first: 
    64    {{{ 
    65    if (1 == $variable) 
    66    }}} 
    67  * A phpdoc block begins with a single line ending with a point.  
    68    All @... statements do not end with a dot. 
    69    @param lines state the variable name. 
    70    Ideally @... lines are vertically lined up (using spaces): 
    71    {{{ 
    72    /** 
    73     * Notifies all listeners of a given event. 
    74     * 
    75     * @param  sfEvent $event A sfEvent instance 
    76     * 
    77     * @return sfEvent The sfEvent instance 
    78     */ 
    79    public function notify(sfEvent $event) 
    80    }}} 
     1Coding standards guidelines [wiki:HowToContributeToSymfony#coding_standards have been moved here].