This document provides some basic rules for indenting C programs: 1) Use meaningful variable names instead of single letters. 2) Name functions to be readable, like describing the action. 3) Align opening and closing braces and add end comments. 4) Use spaces instead of tabs to nest statements and improve readability.
Original Description:
indenting c code
Syntax
Tips for error free programming
This document provides some basic rules for indenting C programs: 1) Use meaningful variable names instead of single letters. 2) Name functions to be readable, like describing the action. 3) Align opening and closing braces and add end comments. 4) Use spaces instead of tabs to nest statements and improve readability.
This document provides some basic rules for indenting C programs: 1) Use meaningful variable names instead of single letters. 2) Name functions to be readable, like describing the action. 3) Align opening and closing braces and add end comments. 4) Use spaces instead of tabs to nest statements and improve readability.
1) Name of variable: Use variable names which are meaningful like
LeftWheelRotations and RightWheelRotations. Don't use variable names such as x,i etc. 2) Name of subfunctions: Use function names which are readable and understandable. Like using void moveForward (int numOfRotations) instead of void fwd(int x). 3) Align of { } : Align the opening { and closing } of each if else, switch, loop. Also write a comment at each closing brace of each statement. if (LeftWheelRotations < RightWheelRotations){ rotationcount++; }// end of if(LeftWheelRotations < RightWheelRotations) else if(LeftWheelRotations > RightWheelRotations){ rotationcount--; }//end of else if(LeftWheelRotations > RightWheelRotations) 4)Use of spaces : Use space in nested statements to make program more readable. Don't use tabs. void main() { int count, sensorvalue=0;
for (count=1; count<=10; count++){
sensorvalue=Read_sensor(); if (sensorvalue < 100){ moveforward(); }// end of if (sensorvalue<100) else if (sensorvalue >700){ moveleft(); } // end of if (sensorvalue>700) }