15 Excellent Programming Habits

1. Ahead of sitting down for coding, you need to have formal or a paper-napkin style of the remedy to be coded. In no way get started coding with out any style unless the code is trivial one particular.

two. Excellent code documentation is as crucial as very good expertise of a programming language. Create short logic for every single significant block of your code as comments in supply code file itself. Its very good to mention creation and modification dates of your plan along-with why modification was essential.

three. Preserving versions of your plan is one more crucial activity. Some present-day programming tools currently have a constructed-in version management. Anytime you make any adjust to your plan, they save its copy as.bak file.

My strategy is to retain three versions of a plan. Say, I have a file plan.c which is utilised by other project group members also. I copy this file as plan.c.old as backup and make one more copy as plan.c.wrk exactly where I do modifications. When modifications are effectively compiled, replace plan.c with.wrk file.

You can also append a date or some explanation phrase to your plan versions like plan260505.c or programReadFnWrking.c.

four. If your project includes a number of supply files then retain a README file stating goal of every single supply files, information files, intermediate and log files (if any). You may well also mention the compilation and execution measures.

five. Ever wondered why your IF statement is not operating as it should really do. Might be your are working with single equal i.e. “=” alternatively of “==” in the situation verify. A very good strategy is to create situation in reverse order. So, your situation should really study anything like this:

if ( 10==i)…. So, if you place single equal sign by error then it will be detected at compilation time only as an error.

six. Even though working with loops and conditional statements, often very first place closing braces corresponding opening braces and then create the inner statements i.e.

1) for(int i=0i<10i++)


four) printf(“i=%dn”,i)


The numbers at the beginning of every single line indicate sequence of writing loop code.

7. Keep away from working with magic numbers. For instance, alternatively of writing

circleArea = three.14 * pow(radius,two)

use following code:

#define PI three.14

circleArea = PI * pow(radius,two)

eight. Use meaningful variable and function names. For e.g. alternatively of working with 'r' use 'radius' to represent radius of a circle. Similarly, function name 'calculateArea' is far better than any cryptic quick name. In a hurry, we may well use quick variable names but the time saved leads to double wastage of time later when you guess for what that quick variable name stands for.

9. Applying print statements for later debugging is a very good habit. But, removing them when final code is prepared is, at times, a risky activity. So, make a function that displays debugging data passed to it. When your final version is prepared, merely comment the internals of this function. So, this calls for modifications only at one particular location.

10. When you are performed with coding, get started optimizing your code. Some of the variables you declared earlier may well not be of use at this stage. Similarly, statements which are not loop dependent can be moved out of loop block. Sound expertise of compiler can also assist in optimizing the code additional.

11. With very good expertise of your operating method and hardware, you can increase overall performance of your plan in terms of resource specifications and so forth.

12. Usually indent your code for clarity and uncomplicated readability.

13. You will also like the thought of organizing project files in into a variety of folders like Supply, HEADERS, MAKE, EXES and so forth.

14. Study the code written by other folks. This will bring to you new programming strategies and what strategy they have followed for the activity for which you have also coded.

15. Final but not least crucial, take backup of your supply-code files so that your work never go waste if really hard-disk crashes or a equivalent mishappening happens.

Show More