Keeping commented-out code is justifiable.
Posted on Sunday, May 24, 2009 at 12:10 AM.Today I read an article that suggested the following:
Commented out code are not comments - Use version control, don't track code changes by commenting them out. Commented out code is schizophrenic code.
To some extent, this is true. It is poor practice to try and maintain extensive source code history through commented-out code. As the author of that article correctly points out, there are numerous software version control systems out there, and most developers are familiar with at least one of them.
But we shouldn't go so far as to say that there's no place for commented-out code. Contrary to what the author of that article suggests, a few lines of commented code can say more to a developer than paragraphs of prose comments. One case where we want to retain such code is when it has a serious flaw that we (or more realistically, a maintenance programmer) don't want to accidentally repeat in the future. By leaving the flawed code there, albeit commented-out and with a quick note describing why the code should not be used, we can leave an effective reminder of the problem.
One other situation I've seen where we legitimately have code in a comment involved a Perl script that was used to generate code for a C array containing certain values. Instead of putting the Perl script in a separate file, where its purpose may not be fully understood, it was stored within the C source file just above the array code that it had generated.
Like goto statements, we shouldn't think that code within in comments shouldn't be used at all just because it can be abused in some cases. It is a technique that has appropriate uses.








