Tuesday, 7 October 2008

Comments Anti-Pattern

Code comments. They are good right? Well yes. However you can fall into the trap of thinking if commenting is good, more comments are better. Comments all 'round. Comments for everyone! The Milkybar comments are on me.

This is the common anti-pattern:
/// <summary>
/// Tests if an order can be prepared for printing.
/// </summary>
[Test]
public void PrepareOrder()
{
...
}
If you multiply that by every public method and or test it can make the class files look a bit jumbled.

So why not refactor by renaming the method and lose the comment?
[Test]
public void OrderCanBePreparedForPrinting()
{
...
}
or even
[Test]
public void Order_Can_Be_Prepared_For_Printing()
{
...
}
I find this far easier on the eye.

No comments: