Why we should always comment code

Adding comments to code can sometimes seem like a “unproductive” exercise. There are always better things to do.There is always the next line of code to write. A few seconds to stare at the wall instead.The meaning of the line of code is clear anyway. What use can a comment be. This works perfectly for a short frame of time and for small snippets of code. But as the time spent away from code increases and the size of the code goes up, things begin to change.

Looking at the same code after a month can make it seem like an unknown language. You have to start all the way from the top and make your way through each line building logic with each line. How helpful would it be if you had the meaning of each line of code beside it in English. Would make it less of a puzzle. Your own code can seem like an alien language if you stay away from it for a sufficient period of time.

Comments also help make debugging easier. Its easier to find places to insert breakpoints if you readily have the meaning of each line of code next to it.

Comments are a lifeline to all those working with old code or someone else’s code. Logic can be quite contextual and personal at times. It’s easier having a dictionary in hand(ie comments) than having to call up the person and bug them about the meaning of all the lines of code that you get stuck at. Comments make the meaning of the sentence clear and quite quickly at that.

What may seem like a tedious waste of time while performing may later go on to save hours of time spent wondering what each line of code means. Wouldn’t there be so much better things to do with that time. Like stare at the wall for instance.