C writing readable 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)
{
.....................
}
  1. Horizontal Rules Differentiate Source Code into Three Parts -
    • Header File Section
    • Prototype Declaration Section
    • Main Function
  2. 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;
          }
   }
}
  1. One can Understand Program if Proper Indentations are Provided.
  2. 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
  1. If You Look at last Three Lines , At First Glance we are unable to Distinguish Corresponding Closing Brace.
  2. So Short but Sweet Comment Can be used to Avoid Your Confusion