Thursday, October 09, 2008

King of Useless Comments

There is a lot of debate among programmers about the proper way to comment your code.  One type of commenting that is sometimes more difficult, is how to comment code that is related to a bug fix.  We've all encountered the types of comments where the programmer states the obvious:

int i = 0;  // Initialize an integer to 0

But "bug fix comments" can sometimes really be longer than necessary.  Here is a typical example of what I'm talking about:

//######################################################
//#
//# Bug #: 1234
//# Date:  10/2/2006
//# Name:  John Smith
//#
//#######################################################
MethodCallAddedToFixBug();
//#######################################################

This type of commenting drives me nuts for a couple different reasons.  For one, it takes up a huge amount of screen space, which breaks up the flow of the rest of the function, and makes it hard to understand.  Can you imagine if a single method had 3 or 4 of these "bug fixes" in them?

Secondly, for all that space taken up on screen, what information did we get?  We got a name, a date, and a number.  What was the defect?  How did this method call actually fix the defect?  We don't know.  Now, if you feel the need to add a comment when you insert code to fix a bug (and I can be convinced pretty easily that there is value to doing that), why not this?

// JS 10/2/2006 - Added call to fix Bug 1234.  This method includs missing validation logic that was causing exception
MethodAddedToFixBug();
Was that so hard?
#    10:02 PM by Nick | 1 Comment |