Programming hints and tips

Debugging - Leave the code better than you found it

One of the best rules of courtesy is that of being a good guest. It says simply that when you visit a place, you should always leave it better than when you arrived. If everybody does this, the place not only survives longer, but actually becomes more pleasant to visit. The same rule can be applied in programming.

When you go in to fix some code, you should make an effort to improve the code, not just to fix it. Try to write the modifications using the same style and commenting techniques as the existing code. If you create a new variable, give it the right name, not i. If you must vary from the existing style, then change toward the standard style that the team has agreed on; that will help the team members the next time one of them has to understand the code.

Update the documentation for any code you modify. Don't leave undocumented code sitting there waiting to trap the next programmer. If you had trouble understanding some of the code, maybe the comments need to be clearer. Expand on what was written to explain it in a way that would have helped you. If you see comments which don't agree with the code, try to find out which is correct; and make them agree! You may uncover extra bugs this way (without waiting for some customer to report them). If not, then you will certainly make the code easier to understand next time.

If every time you fix a bug, the code gets a little better, rather than just a little bigger, then you can be confident that you will eventually run out of things to fix.

Want to:
Read more from the soapbox
- Read Awk Words.
- Look at my AWK scripts.
- Read Robert's Rules Of Coding.
- Go back to the front gate.
- Visit another wagon.

Make a product that even an idiot can use, and only an idiot will want to.
Page maintained by Rob.