Factor Language Blog

The golden rule of writing comments

Tuesday, April 8, 2008

This is something I’ve wanted to say for a while, and I think many (most?) programmers don’t realize it:

Never comment out code.

Comments are for natural-language descriptions of code, or pseudocode maybe.

If you comment out some code, then the parser isn’t checking the syntax, the compiler isn’t checking semantics, and the unit tests are not unit testing it.

So the code may as well not work. Why have non-working code in your program, especially if it’s not called anywhere?

But perhaps the code is there so that you can see the what the program used to do. In that case, just fire up your favorite graphical GIT/SVN/P4/whatever frontend and check out an older revision.