Showing posts with label work. Show all posts
Showing posts with label work. Show all posts

Wednesday, May 23, 2007

Coding Style ...

I have never thought much about coding style before i did my NOSIP in Novell. But once i started coding for ldtprecord, according to the coding style suggested to me by nags, i was surprised to see how nice and neat the final code looks.

Some tips/tricks for nice coding skills are,

1. Do spend some time to think about the variable names and the function names. This sometimes might be bit boring, especially when you want to concentrate much on the program logic and performance. But this is Rule 0 for coding conventions. A variable name "k" can imply anything like "kappa, kozhukattai, katthu, kaadhal, kerala, kozhuppu..." to someone who might have to read your code later. This is again mentioned here clearly. Many thanks to emacs, you can always use the auto complete, if your variable name is too long. :-) .

2. The actual coding convention depends much on the language and the standards your team is using already. The following style won't work for someone, whose team is already using a totally different style.

A few examples for C is posted here .

Sample Code 1 :

if (a == 5) {
    b = 10;
}
else {
    b = 20;
}


Things to be noticed in the above snippet are.

1. A space between if and "(" .
2. Space in both the sides of the comparison operator.
3. Space between ")" and "{"
4. Space between both the sides of assignment operator (line 2 & 5) . This is true for almost all the operators.
5. Proper indentation of lines 2 & 5. If you are using emacs or vi, check here for your .emacs or .vimrc file .

Well, your code will compile and run even if you don't give these spaces, but a program coded with a bad coding style is equivalent to an inefficient code.

Sample Code 2

Let us have a function which takes two integers and returns their sum .
The code should be like

int add_numbers (int num1, int num2) {

    return (num1 + num2);
}


The function call will be something like,

int sum;
sum = add_numbers (10, 20);

Things to be noticed in the above snippet is

In the first line in the function declaration,

1. The function name should be as clear as possible.
2. A space between the end of function name and "(" .
3. Spaces are given after every "," in the function argument list.
4. A space is given between ")" and "{".

In the second line in the function declaration,

1. A space before "(". [ This rule is almost global. Apply it everywhere whenever you use "(" ] .
2. There is a space on both the sides of the addition operator. This is again almost global. A space between both the sides of operator makes the code look real neat.
3. The indentation about which was mentioned earlier.

But yes, if your girl friend is a geek or a nerd or a psycho or a fundoo, then you better go for this. ;-)

#define MAGIC "eilouvy43605321"
#define _(p,o,q) (t o#p[0])?(q)
#define __(p,o,q) _(p,o,t-q)
int main(){int t, i; for(i=8;i>0;i--)printf("%c", MAGIC[(((t=(MAGIC+7)[i-1])=='_')?62:_(.,==,63):_(@,==,64):__(a,>=,'a'+36):__(A,>=,'A'+10):(t-'0'))]);}

Note :: I wont say the coding style i use is the perfect one. It always depends upon what your team was using till now and how easy it is to read, debug and maintain the code.

Useful Links :
The guide coding standards in GNOME is really a nice one.
Even better was this one i found recently. Though i didn't read it completely, it was quite interesting.
This article was short and sweet.

Friday, January 19, 2007

Quiz is finally over :) :)

If at all if someone gives me the right to scrap three events from pragyan i will surely opt for junkyard wars, technical quiz and udaaan . These three are actually very good events when you are a participant. But when if you are the one who is responsible for the quiz software for these events, that too with all three events starting one after another , surely you will go mad.

Everything started when i made a foolish decision to attend a delta meeting . The meeting is to discuss about delta induction. I was trying to make a quiz manager at that time ( inspired from manu's quiz manager ) and thought i will do one for delta induction, which can be used for pragyan also . ( never realized this was such a big blunder ) . Somehow managed to changed few things in manu's code and finished the delta inductions.

The whole headache started few days before pragyan . All three event manager contacted us few days before their events. Actually i was kind of shocked by what they asked me . One wants a timer while the other says i dont need a timer :( :( . Err what is your fscking problem if there is a timer :(.

The worst part i did not code a single line in the pragyan quiz manager :( . It is coded by one of my junior and i saw the code just 3 hrs before the event. Of course i went mad , called up my junior every now and then asking to explain about what the code actually does.

Finally junkyard wars started 4 hrs late , udaan 5 hrs late and tq some 14 hrs late :P

Took a resolution that will never take up any more work in pragyan :( .