How to write readable and eye catching C Program ?
Tips For Writing Readable And Eye Catching C Program
Tip 1 : Use Stylish Comment to Specify Title Of Program !!
/********************************************* * Title : Your Title * Date : DD/MM/YYYY * Program By : Your Name *********************************************/
Or
/** * Title : Your Title * Date : DD/MM/YYYY * Program By : Your Name **/
Tip 2 : One Should Use Horizontal Rulers To Differentiate Different Modules
#include< stdio.h> #include< conio.h> //---------------------------------------- int add(int,int); int sub(int,int); int div(int,int); //---------------------------------------- void main() { ............................ } //---------------------------------------- int add(int a,int b) { ..................... }
- Horizontal Rules Differentiate Source Code into Three Parts -
- Header File Section
- Prototype Declaration Section
- Main Function
- Horizontal Rule makes Program more Readable
Tip 3 : Must Specify Function Description Before Writing Function Definition.
/*----------------------------------------------- Search Function : Used to Search Element -----------------------------------------------*/ int search() { ..... ..... ..... }
Tip 4 : Use Proper Indentation [i.e Space]
if(condition) { for(i=0;i< n;i++) { Statement 1; Statement 2; while(i<5) { Statement 3; Statement 4; Statement 5; } } }
- One can Understand Program if Proper Indentations are Provided.
- In Above Program one can Easily Understand Statements Under if,for,while.
Tip 5 : Provide Comment After Nested Closing Braces.
if(condition) { for(i=0;i< n;i++) { Statement 1; Statement 2; while(i<5) { Statement 3; Statement 4; Statement 5; } //end of while }//end of for }//end of if
- If You Look at last Three Lines , At First Glance we are unable to Distinguish Corresponding Closing Brace.
- So Short but Sweet Comment Can be used to Avoid Your Confusion