On Comments, Yet Again

time to read 2 min | 388 words

After making such a point about commenting being mostly noise, and that code should be able to stand on its own, I found myself adding the following comment (related to this issue) to Rhino Mocks.

//This can happen only if a vritual method call originated from 
//the constructor, before Rhino Mocks knows about the existance 
//of this proxy. Those type of calls will be ignored and not count
//as expectations, since there is not way to relate them to the 
//proper state.
if(proxies.ContainsKey(proxy)==falsereturn null;

There is just no way that I'll remember in 2 week (let alone months) why this is important. Then again, the test for this piece of code is called "MockClassWithVirtualMethodCallFromConstructor", so this should probably be good enough.

Damn, but I love to work on code that is covered with tests. It was a ten minutes affair from getting the test to fail to finding exactly where the problem is, and then it was a simple matter of escelating the call stack until I had a good enough view on what was happening. Two lines of code (and 5 lines of comments) later, I got a passing test.

Three minutes afterward, I was uploading a new release to the website. This is the best thing about doing TDD, I know that I can't break the system without knowing about it. And if I do break something that I don't have a test for, well, if I don't have a test for it, then I'm probably not going to need it after all, so it wouldn't bother me. Perfect :-)