Minimal

stressed for motivation and achievement

2006-03-25

 

BUG #171: Blank title didn’t work here

The other day at work, I came across a diktat stating that any bug fixes should be given a code comment pointing the reader to the relevant issue in our defect tracking system. Well, until someone explains the rationale to me, I’m going to ignore that.

To look at how dumb this is (IMHO), here are a couple of analogies to consider:

So, why the hell should I litter my C# code with comments that refer to a bug that’s no longer exists? What do I care if there was once a bug there? What’s important is that the code now works—we can record the bug fix in our check-in comments. What valid reason might I be overlooking for this behaviour?

Update: the diktat is no longer a diktat; more a recommendation. And it now sits alongside another recommendation that says “where reasonable, write a unit test to prove the existence—and resolution—of the bug”. Result. :)


Comments:
It is often the case that the reasons for a change are not evident to the next person who works on a piece of code. They might change it but unwittingly reintroduce whatever problem your change was solving.

I don't agree with the diktat, I'm just trying to think of a rationale for it. There are odd times where I have noted a bug number next a change to help somebody understand why I changed it. But those times are few and far between and almost always when I've been working in "someone else's" code where the ideal solution would have been a more significant refactoring of the whole lot.
 
Yeah, I think you just hit on the point I was trying (and totally failing) to make - the better solution is often to make sure the code just plain makes sense. Refactor it if you have to (and have the time). On the occasions when you need a comment in code, then a reference to a more in-depth analysis in a bug report can be useful, but it shouldn't have to be every time.
 
We used to have exactly the same policy at Nonlinear. Loads of comments entered the code with bug numbers next to them. There were two conclusions that I drew from this:

1. The need for a comment within a function can often signify that the function could be re-written in such a way as to illustrate its algorithm better. Refactoring can make a lot of this stuff clearer.

2. I once found a comment in the code which described very clearly why something was in there, and which bug it had fixed. I realised that the comment was actually taking the place of a test case. I turned it into a test case, which duly failed, and then I discovered that other changes, had re-introduced the bug. The lesson? Comments don't avoid bugs, long-term. Test cases are better.

Ignore the dictat, write self-documenting clean code and test-cases. I've been doing this since January and it's absolutely smashing!
 
Ash said: "We used to have exactly the same policy at Nonlinear. Loads of comments entered the code with bug numbers next to them."

Not at my desk, they didn't. ;-)
 
There was a time.
 
I agree with Ash on this one, bugs should be documented with tests (which fail until the bug is fixed and then ensures the fix isn't accidentally removed) rather than code comments.

Very few people update code comments when they update code, as a result the comments become out of date and ignored.
 
We used to have a chap who left fruity comments in his HTML code. Then one day we realised that this was, of course, being downloaded to the users machines and was clearly visible in the source.
 
[url=http://dcxvssh.com]KTIWrNRFTUWq[/url] - XrMnAUKZmfKsVtO - http://hhmgziigpu.com
 
Post a Comment



<< Home

Archives

April 2002   May 2002   June 2002   July 2002   August 2002   September 2002   October 2002   November 2002   December 2002   January 2003   February 2003   March 2003   April 2003   May 2003   June 2003   July 2003   August 2003   September 2003   October 2003   November 2003   December 2003   January 2004   February 2004   March 2004   May 2004   June 2004   July 2004   August 2004   September 2004   October 2004   November 2004   December 2004   January 2005   February 2005   March 2005   April 2005   May 2005   June 2005   July 2005   August 2005   September 2005   October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006   January 2007   February 2007  

This page is powered by Blogger. Isn't yours?