Now I am developing A CRM for SIEMENS Bangladesh Corporate office. Actually I am customizing and adding some feature with vtiger( Now working with sugar. it’s really good ) CRM.
I passed one week studying on its coding style. I thank those guys who develop it. Every module they develop with a great care. But I am upset about there coding arrangement.
I always try to follow a slandered coding style. I feel if the coding is well decorated it always increase the performance and value.
Especially I was impressed with the coding style of PHPBB and I followed this standard more then six month. Then I start my own style.
First of all I like to arrange code with double TAB. It looks much readable to me. For variable naming some coder like Camel Method But I use under score to differentiate the words what maximum open source programmers do.
$countryName = ‘Bangladesh’; // Camel Method
$country_name = ‘Bangladesh’;
Now looping and conditions . It is very important to make it clear with coding style.
If ( $flag = $module ){
do_stuff();
}
for ( $i = 0; $i < $size; $i++ ){
do_stuff();
}
while ( $i < $size ){
do_stuff();
}
do {
do_stuff();
}while( $i < $size )
It is good practice to use space after each conditional statement. PHPBB standard always keep brace in separate line. This is also a good practice.
//PHPBB styles
for ( $i = 0; $i < $size; $i++ )
{
do_stuff();
$i++;
}
For function or class I like to do something more. May be some body feel bore with it. But I feel comfortable with this decoration. I put a line before starting a function and when I finish then also add a line. So it look’s like a block of coding. And at the end brace I write the function name with definition if need with comments again. Because it saves me to be confuse during debugging. Same policy I use for classes.
# This comments go for class
//=======================================================
class class_name{
# This comments go for function
//======================================================
function my_function(){
// Class Knowledge Center
}//function my_function
//======================================================
}// class_name
//=======================================================
Comment makes the coding more readable. But I don’t like using unnecessary comments. Unnecessary comments always annoy me. For the top of the document I always use the following style
/*========================================================= *************************************************************************
# Company name:
# Session:
# History
*************************************************************************
==========================================================*/
For short comment inside of a function hash (#) or double (//) slash is pretty good
# Calculating total salary
$salary = $total_days * $income_per_day;
Before begging of a block I use the following style. Actually PHPBB use this style.
/*
* Short description of the block
**///
Hope this post will help you guys!
Mentors Award Q3 2008
Top Website Coder