Professional Documents
Culture Documents
CODING STANDARDS
Naming Conventions:-
1) camelCase should be followed for all ‘Variable’ declarations. Eg: $objUserArray
2) PascalCase should be used for Class names. Eg: $MyClass
3) All names should be in English and grammatically correct. Names like “foo” and
“tmp” should be avoided since they do not describe anything. Names should not
contain numbers, Numbers should be described with letters unless there is a good
reason for it.
4) Function names should also follow camelCase.
Eg:
setText(..);
id();
setID();
getTheValuesForThis();
Wherever applicable use name starting with ‘get’ or ‘set’ as and when the
functionality is to ‘get’ a value or ‘set’ a value respectively.
5) Constants should be constructed by only capital letters, ‘_’ should be used to separate
words.
Eg:
define( "MY_CONSTANT", 42 );
6) For Arrays, use the prefixes to denote the content type of the array and have the suffix
"Array" added. eg: $objUserArray
1) For Braces {} use Unix styles of including the opening brace in the same line as the
expression. And there should be a space before the brace starts.
Eg:
public function generateAssetCode($intAssetId, $blnAssetFlag = true) {
...
return $strAssetCode;
}
Page 1 of 4
CODING STANDARDS & UNIT LEVEL CHECKLIST
2) Single space is required after any comma. (Instances like comma separating
parameters in a function signature etc)
3) Empty lines should be used to group variables and code lines which have a
connection. Variable names which are grouped should be indented to the same level.
4) Prefer Ternary operator if it is a simple IF condition.
5) Nested if statements should always use {}. If you have a lot of ‘if, else’ statements
these should probably be replaced with ‘case’ statements.
6) Use Comments judiciously. Proper comment should be given for scripts, functions
and even variables if required.
Eg for Script:
/**
* Short description
* Multiple line detailed description.
* @project Fortuneprops
* @package xyz
* @author Your name here
* @version 1.0.0
*
*/
Eg for Method:
/**
* Generates an asset code based on AssetId
*
* @param integer $intAssetId This is the asset_id needed to generate the asset code
* @param boolean $blnAssetFlag This tells us if we're generating an asset code,
defaults true
* @return string $strAssetCode - This is the generated asset code
*/
public function generateAssetCode($intAssetId, $blnAssetFlag = true) {
...
return $strAssetCode;
}
7) Indent Consistently. Use indentation consistently to enhance the readability of the
code. When elements carry over more than one line of code, indent the contents of
Page 2 of 4
CODING STANDARDS & UNIT LEVEL CHECKLIST
elements between the start tag and the end tag. This will make it easy to see where the
element begins and ends. Also, use indentation to align code at attribute names
8) Standard Tab size would be 4.
Page 3 of 4
CODING STANDARDS & UNIT LEVEL CHECKLIST
Page 4 of 4