Debugging with comments

Programmers sometimes think of commenting their code as a chore. “Can’t people just read my code,” they ask, “and see what I am doing?”

But it’s not that simple. Not only is commenting good for communicating with others, it is also an excellent way to communicate with yourself.

When you write out, in plain English, exactly what you are doing, you understand it better. Doing a good job of explaining something is one of the best ways of understanding it yourself.

Also, you might find that when you go through the effort to do this, you uncover flaws in your own code or its underlying algorithm. More than once, I have started to comment my code only to realize that I could now see an error or unhandled case in the program itself.

In short, commenting your own code is one of the best ways to debug it.

Leave a Reply

Your email address will not be published. Required fields are marked *