Posted by: uttamkumar | July 25, 2008

coding standered & convention

or a team to work effectively and to share ownership of all the code, all the programmers within the team need to write the code in the same way or same programming style.These programming style refers to a set of guidelines,rules that one should follow in the team.programming style used in a particular program may be derived from the coding standards or code convention of a company/organization.

Good coding standards are important in any development project, particularly when multiple developers are working on the same project. Having coding standards helps to ensure that the code is of high quality, has fewer bugs, and is easily maintained.here are coding standered and convention that one should follow while developing a PHP program.

Comments convention
  • each php file should have Header comment block.This block should contains short description of file,category,package,auther,coyright etc.
  • each function block should have Function comment block.This bloc contains brief description about task perform by function,parameter passed and data type n identifier which function returns.
  • Inline comment can be helpful in case of complex logical block of code.
Naming convention
  • Identifier names should be explanatory, and should be in word-case. Also the first letter of the variable or parameter or IDs must tell the nature thereof.
    • For Example
      Class: ClassName
      Object: oObjectName
      Function Name: functionName()
      Private Method: _MethodName()
      Constants: CONSTANTNAME
      String Variable: sVariableName
      Array Variable: aVariableName
      Integer Variable:$ iVariableName
      Float Variable: fVariableName
      Boolean Variable: bVariableName
  • Global variable should contain package name in uppercase followed by 1 underscore and identifier name.

    For Example

    PEAR_destructor

Coding convention
  • Use an indent of 4 spaces, with no tabs.This helps to avoid problems with diffs, patches, SVN history.
  • lines at approximately 75-85 characters long for better code readability.

Leave a response

Your response:

Categories