CODING STANDARD

Conventions

Example

Always use Pascal Conventions FirstName, DateOfBirth
Directory Name – Lower Case , use ‘_’ for word separation product_types
File Name – Lower Case , use ‘_’ for word separation new_enquiry.php
– For ‘class’, ‘library’ and includes (which are used only to include in other files) file name must use “.inc.php” extension.
-Prefix Class Files with ‘cls_’
cls_enquiries.inc.php
Function Name –
– Case : Pascal Case
– Use prefix with ‘fnc_’
fnc_GetUserType()
Class Member Variable Names –
– Case : Pascal Case
– Use Hungarian or any other notation as Prefix to distinguish Data Type
sUserName
Function Argument Variable Names –
– Case : Pascal Case
– Prefix with arg_
– Use Hungarian or any other notation as Prefix to distinguish Data Type
arg_nProductType
Define Constants or Variables Used As Constants – Case : Upper Case LEADTYPE
Define Global Variables as –
– Case : Pascal case
– prefix with g_
g_Database
Define Global Variables as –
– Case : Pascal case
– prefix with g_
g_Database
Array –
– Use double quotes to access/define array elements
$myArr[0] = “value” e
Braces ‘{}’ –

– Always put opening brace in the next line.
– Use brace in if, while, etc.. even for one line.

if(condition…)
{

}
– Proper Indentation should be applied for all part of the code, Tab should be used for each if, while, for etc.

– Code should be properly Aligned.

for(…)
{

}
$mData = 0;
$dddddddddd = 0;
– If Else nesting –
– Start else in the next line after the if closing brace ‘}’
if(condition…)
{

}
else
{

}
-Switch –
– default case should always be present and triggers an error if it should not be reached, yet is reached.
conditional operator (?:) –
– Use conditional operator only for simple conditions.
– For complex instead of this use if.. else..
Document Null Statements –
– Always document a null body for a for or while statement so that it is clear that the null body is intentional and not missing code.
while ($dest++ = $src++){
// VOID
}
Commenting Code –
– All ifs, whiles, fors, etc. should be well commented and have a definitions for its purpose.
// Following If is used for example
if(…)
{
……….
}