Home Categories Submit Republish Tools Links Credits Contact
Popular Articles
 
     
 
 Categories
 
 
Submit your articles online!

15 Good Programming Habits

By: Syed Feroz Zainvi

Published: June 24, 2007
Link To Article Link To Article  E-mail Article E-mail Article  Republish Article Republish Article
1. Before sitting down for coding, you must have formal or a paper-napkin design of the solution to be coded. Never start coding without any design unless the code is trivial one.

2. Good code documentation is as important as good knowledge of a programming langauge. Write brief logic for each major block of your code as comments in source code file itself. Its good to mention creation and modification dates of your program along-with why modification was required.

3. Maintaining versions of your program is another important task. Some present-day programming tools already have a built-in version management. Whenever you make any change to your program, they save its copy as .bak file.

My approach is to maintain 3 versions of a program. Say, I have a file program.c which is used by other project team members also. I copy this file as program.c.old as backup and make another copy as program.c.wrk where I do modifications. When modifications are successfully compiled, replace program.c with .wrk file.

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

4. If your project contains multiple source files then maintain a README file stating purpose of each source files, data files, intermediate and log files (if any). You may also mention the compilation and execution steps.

5. Ever wondered why your IF statement is not working as it should do. May be your are using single equal i.e. "=" instead of "==" in the condition check. A good approach is to write condition in reverse order. So, your condition should read something like this:

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

6. While using loops and conditional statements, always first put closing braces corresponding opening braces and then write the inner statements i.e.

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

2) {

4) printf("i=%d\n," i);

3) }

The numbers at the starting of each line indicate sequence of writing loop code.

7. Avoid using magic numbers. For example, instead of writing

circleArea = 3.14 * pow(radius,2);

use following code:

#define PI 3.14

circleArea = PI * pow(radius,2);

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

9. Using print statements for later debugging is a good habit. But, removing them when final code is ready is, sometimes, a risky task. So, make a function that displays debugging information passed to it. When your final version is ready, simply comment the internals of this function. So, this requires changes only at one place.

10. Once you are done with coding, start optimizing your code. Some of the variables you declared earlier may not be of use at this stage. Similarly, statements which are not loop dependent can be moved out of loop block. Sound knowledge of compiler can also help in optimizing the code further.

11. With good knowledge of your operating system and hardware, you can improve performance of your program in terms of resource requirements, etc.

12. Always indent your code for clarity and easy readability.

13. You will also like the idea of organizing project files in into various folders like SOURCE, HEADERS, MAKE, EXES etc.

14. Study the code written by others. This will bring to you new programming techniques and what approach they have followed for the task for which you have also coded.

15. Last but not least important, take backup of your source-code files so that your effort don't go waste if hard-disk crashes or a similar mishappening occurs.

Syed Feroz Zainvi has obtained M.Tech. (Comp Sc & Engg) degree from Indian Institute of Technology, Delhi (INDIA). His areas of interests are distributed computing, computer graphics and Internet Technologies. Currently, he is involved in Software Project Planning, Development and Management. His other interests include writing for magazines and contributing utility software on Magazine's CDs. He also have flair for teaching computer science with new teaching methodologies. His web-page URL is http://www.geocities.com/zainvi_sf



Visitor Comments

Post Comment Post A Comment
What do you think about this article? Do you agree or disagree with it? Be the first to comment on this article, and share your thoughts with the world. No registration is required to post comments.

Article Icon Computer Programming - A Brief History
If a definition of a computer is that it is a piece of equipment that needs to follow various directions in order to carry out the tasks required of it, then the history of computers can be traced back to...
Article Icon Top 10 Elements Of Open Source Development
Open source development has undergone lot of changes to emerge as powerful in recent times. Today when software's are getting expensive consistently, open source techniques can eloquently help in making...
Article Icon The Usefulness Of Each IPhone Entertainment App
Apps with break through features like Audio/video playes, music players, and social media apps.
Article Icon Form Vs. Function? Which Is More Important In GUI Development?
During GUI training, students learn about graphical user interfaces. These are interfaces that allow users to interact with a computer in ways other than only typing and text.
Article Icon The Development Of IPhone Enterprise Apps
The Enterprise apps interact with the home server to get sensitive data of your customers.
Article Icon Alarm Clocks And Online Collaboration
Have you ever bought a piece of equipment that you thought would come in very handy only to leave it lying around for months because you could not figure out how to set it up? Or not set all the functions...
Article Icon IPhone Web Application Development
Since the creation of personal computers and the World Wide Web, technology has moved on to the creation of various computer and web applications that users can enjoy while using their personal computers or...
Article Icon Hire Android Developers
Google Android is a platform for professionals, offering a wide range of options and many opportunities for development of high quality Android applications. For the highly advanced and smart choices, the...
Article Icon Who Becomes An IPhone App Developer?
It's not a classic job title like fireman, president or teacher. Exactly who becomes an iPhone app developer, and what makes the job attractive to them? Read below to learn about the personality traits...
Article Icon Characteristics Of IPhone Application Developers
iPhone application developers share a common list of traits that serve them well in their chosen profession. Read below as you learn what makes these 'techies' so good at what they do, and then commission one

Article Icon Everything Is Happening For The Good
When we feel that something has gone wrong and are very much disappointed then people will console us saying "Probably, there is some good in whatever is happening to you." Here I would like to comment on this
Article Icon Is Your Marriage Sinking?
Reading this article does not necessarily mean that if you are married then your marriage is sinking. However, if you believe that living under a single roof means you have to compromise with your spouse...
Article Icon Uncommon Facts / Rules Of English Langauge
English is an international langauge. It has so many grammar rules and each rule with many exceptions. Usually, we write English without paying much attention to these rules and exceptions. But, its good to...
Article Icon Just Remind Yourself
This is one more article on "Organizing and Enjoying Your Life". Much has already been written about this in magazines, books and on Internet. In this article, I am summing up the important points; some of...
Article Icon 10 Ways To Learn A Software Package
Following tips help you to learn a software in lesser time and in an efficient manner:1. After installing a software package, look for any README file in the installed folder. Besides company and product...


Print This Article Print This Article
Add To Favorites Add To Favorites
Cite This Article Cite This Article
 
 
Home | Categories | Submit | Republish | Tools | Links | Credits | Contact | Privacy Statement | Terms Of Use
Copyright © 2012 InfoServe Media, LLC (DBA PopularArticles.com). All rights reserved.