It’s My Story!

Smart coding style always increase the value of a coder

August 29, 2007 · 11 Comments

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! :)

Categories: Coding Style

11 responses so far ↓

  • Fuad Ahasan Chowdhury // September 9, 2007 at 3:56 pm | Reply

    hey rubel great sharing.. keep rolling man.. ar btw.. y don u make some ‘girls script’ man!! which actually can help us ;) hehehe

  • Rubel // September 10, 2007 at 7:23 am | Reply

    Thank you fuad!!!
    This is actually technical place.
    It you need it. Contact me personally.. ;)

  • rayhan // September 13, 2007 at 5:59 am | Reply

    Hi rubel bhai,

    Your coding standard is very nice for debugging period I have no doubt on it. But what if you add type symbol with variable. Like

    for integer type:
    $CommentId => $iCommentId or $icomment_id

    for string type
    $name => $sName or $sname

    for array type
    $posts => $aPosts or $aposts

    I follow $iCommentId format.

  • zakir // October 30, 2007 at 10:48 am | Reply

    you know you are genius………….your coding is lucrative……kip it up…………….

  • Rubel // October 31, 2007 at 4:42 am | Reply

    ;)

  • manchumahara // December 4, 2007 at 9:00 pm | Reply

    I always follow the phpbb style coding…I like phpbb engine…If u have free time then plz have a look in this bangla phpbb forum…
    http://forum.amaderprojukti.com/index.php

  • Idetrorce // December 15, 2007 at 12:33 pm | Reply

    very interesting, but I don’t agree with you
    Idetrorce

  • David Spreekmeester // August 22, 2008 at 3:45 pm | Reply

    Nice post. Just wanted to add a note about the documentation style: the syntax you mention as PHPBB uses it, is the PHPDoc format. Using this format can be very practical for integration, for instance the Eclipse IDE automatically shows only the description line of a PHPDoc block, but also software like NaturalDocs (open source) can generate HTML documentation of your code automatically if you use the PHPDoc style.

  • venkat // April 23, 2009 at 1:47 pm | Reply

    A few notes:

    for ( $i = 0; $i < $size; $i++ )
    {

    do_stuff();

    $i++;

    }

    Why couldn’t you use i+=2 instead of incrementing i twice?

    Do you realize If ( $flag = $module ){ Blah Blah } will always return true? why use assignment here?

    i just wonder.

  • Rubel // April 23, 2009 at 2:44 pm | Reply

    he he…Well mate,
    I was clarifying about to write curly brass per line that followed by phpBB. For example

    “While(1)
    {”

    instead of

    “While(1) {”

    See the text ” PHPBB standard always keep brace in separate line. This is also a good practice.”

    You seems very expat in if structure. But we are discussing about the coding style not logical implementation. ;)

  • sandrar // September 10, 2009 at 1:28 pm | Reply

    Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.

Leave a Comment