Thoughts, Tips and Tricks on what I'm currently do for a living. Currently most of my spare time is spent on contributing to Akka.NET.

Monday, May 21, 2007

Insert Do-nothing comments

Always insert a //Do nothing comment in places where the intention is that nothing should be done. Let Me show you why by an example. Assume you have a constructor for a Control that inherits WebControl and all you want to do is changing the default tag (which is Span).
public MyControl()
   :base(HtmlTextWriterTag.Div)
{
}
When someone else reads this code (or you in a month or so when you've forgotten all about it) they might wonder if this code has been finished or if there is something missing in the constructor. By adding a comment, you show for anyone reading the code that there shouldn't really be any code inside the constructor.
public MyControl()
   :base(HtmlTextWriterTag.Div)
{
   //Do nothing
}
I have a code snippet for this so I just need to type don and hit tab twice and //Do nothing is inserted.

No comments:

Post a Comment