Some tips/tricks for nice coding skills are,
A few examples for C is posted here .
Sample Code 1 :
if (a == 5) {
}
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 .
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 “(” ] .
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 :
Thanks! I`m kind of in the same situation as you and the info was very useful!
Pingback: int num2