This tutorial is about some of the coding procedures that I learnt...
1. COMMENTS
Comments are the blocks that explains about what something does...
For example,
/* file.c a one line descriptor of the contents of the file copyrights, authors... */ /* function_name() one-liner for the function about assumptions and limitations, etc */Comments helps in understanding of what the code does... Comments should not explain about how does the code work... It is only needed when the code is complex... Simpler code needs just a one liner statement
2. INDENTATION
It is second most thing that is very important... If the indentations are poor, It becomes very difficult to decode where the braces starts and braces end, and lot more...
Indentation can be a char space or a Tab... Tabs are 8 characters... If the code has too much nesting of loops, dont use Tab Indentation because it will makes difficult to read the code .
3. BRACE STYLE
The placement of braces is not so important but still it makes the code look pretty. The opening braces should be on last of the line and put the closing braces at first. For example,
if ( x == y) {
....
} else if (x > y) {
.....
} else {
.....
}
If condition is shown in the example,. Likewise, it goes for while, for and switch as well...
However, for functions it can be at the beginning of the next line. For example,
int function ( ....)
{
.........
}
NOTE: Do not use open version of statements. For example,for ( x = 0 ; x < 100; x++) loop ( ); next( );
While using this you can feel bit easy but when somebody tries to modify your code, he might get tripped.
So always use
for ( x = 0 ; x < 100; x++) {
loop ( );
}
next( );
4. C TYPES
Always use the standard C types... For example, If you have a struct pointer, just name it as such.
Use:
struct fun {
int i;
....
};
and not:
typedef struct {
int i;
....
} fun;
It does means that typedef shouldn't be used. It can be used for industry-recognized types like ushort (unsigned short) and so forth..
5.NAMING
use short local variable names within function. keep variables in the same class of length.
Globals ( both function names and variables)used across source files need to be have longer, more descriptive names.
6. ISO void *
When dealing with a generic pointer value, use ISO void pointers. Do not do maths with such a pointer. gcc might treat it as a "char *" , but don't assume that all the world is gcc. If you need, typecast them to (char *) and then do maths.
---------------------------------------
These are some of the coding procedures that I learned.. They are still lot more. If anyone knows some other procedures, Do share with us..
Hope you all find these very useful.. Any suggestions are welcomed...


Sign In
Create Account


Back to top









