Friday, December 16, 2005

Campaign for the abolition of commented out code

AskTom recently had a post on the ten commandments of Oracle development. The commandment that generated the most comment was on commenting code.

I do agree with useful comments in code though I'm sure I don't do it as much as I should (New Year's resolution time). However my personal pet hate is commented out code. These days I general use a pretty editor with syntax highlighting, so it's a lot easier to ignore all the 'green stuff'. In the days of black and white editors (and some people still LIKE vi), it is very easy to lose track of what is 'real' code and what was code three years ago but isn't anymore. [I've read that some 'spawn of vi' editors do have syntax highlighting, but all I get is plain vanilla vi.]

IMHO (and that's all this blog is) dead code belongs in source control history and no place else. If you absolutely MUST comment out code, use the -- form of comments so that people don't have to page up and down to work out whether the code they are looking at is still being used or not.


6 comments:

Anonymous said...

+1

Seeing swathes of commented out code when we have a perfectly good version control system irritates the heck out of me. I mercilessly eliminate such guff on sight.

The only thing worse than commented out code is the practice some people have of renaming obsolete files (e.g. Class.java to Class.java.old) because they "might" need to refer to them again (and presumably don't trust or want how to learn to use the version control system).

Pete Scott said...

Gary
We write comment headers into all of code - including view DDL ! this gives us who, what and when for all changes. It used to keep the ISO auditor happy that each code change that required a code fix could be tracked from problem to code change - then they asked that we also commented the lines that changed and why :(
But I agree, block commenting out of code is highly unreadable unless you use a IDE or editor that supports syntactic colour.

William Robertson said...

Yes, Vim does syntax highlighting. I had to tweak my psql.vim a bit to get it how I like it but it works. Redhat Linux and doubtless others now come with "vi" set up as an alias to Vim, so I think the days of black & white code are numbered.

Robert Vollman said...

It's worse in C/C++ where the commented out code is in one of these:
#if 0
#endif

That won't even change colour in most IDEs.

However, there are some fancy IDE's that have little "minimise" buttons on the side to minimise comment blocks.

I have to agree that there is seldom any use for commented out code in final, production versions of code.

Anonymous said...

I'm on a campaign, too: to get people to link to the new Dizwell Forum instead of the old one!

:-)

The correct link should be to http://www.dizwell.com/forum. Cheers.

SydOracle said...

Howard,
Done my link. Now you just tell that slacker Tom Kyte to update his link on AskTom - Other Resources :)
Everyone knows that if you have a link from AskTom, your traffic goes through the roof.