The one thing that I have never stopped hearing in my programming classes, even upper level ones, is something along the lines of:

I was adding comments to my program…

Countless numbers of the people I have helped with programming do not add comments while they’re actually writing the code.

Instead, for some reason, they have learned that going back through your program and adding comments once it’s done, is acceptable.

It’s Not Acceptable

Sure, you’re little 20-line program might be understandable to you after you write the code. Hell, it might even be understandable if you go back through it in a year.

But that is still no excuse for such a bad habit.

What happens when you’re writing a several hundred line program? And even after a day, you hardly can remember what a section of code does? Or even worse, working with a team of people who are programming the same thing.

Add Comments While Writing Code

I’m not sure if this bad habit has been caused by the teacher’s neglect for enforcing good program comments, or if it’s just students being lazy.

But, if you want to be a successful programmer, or even an intermediate one, you need to add comments while writing your programs!

It doesn’t take long, in fact it might even say you the time you take trying to re-understand your program after you have finished.

A comment now will save you later!

Stupid Comments Don’t Exist

Hopefully now that I’ve persuaded you (I know, I didn’t try very hard) to start adding comments while you write your code, I can tell you that there is no such thing as a stupid comment.

The same goes for a redundant comment, they don’t exist, every comment in your program is helpful, and there for a reason.

If you feel that you might not remember what a variable is for (especially variables used in equations), then add a comment.

What you might forget, someone else will forget.

Write Meaningful Comments

So, I know I said that there is no such thing as a stupid/redundant comment, I actually lied about that.

If your comments are not meaningful, like your variable names, then they’re stupid, worthless, and need to be changed.

That means, do not do this:

int x; // Integer x

Like, really? No shit.

Instead, try something like:

int x; // Distance between variable y and variable z

This comment tells us a whole lot more, now we actually know what the variable x represents, and how we can calculate the value.

Also, remember that meaningful variable names (along with comments) are crucial to writing nice and easy to read code, so instead of calling the variable x, try:

int distance; // Distance between variable y and variable z

Or something similar, that gives more meaning to the variable.

You can do it.