Why I (Occasionally) Use Empty Statements

Filed under: Blog Comments: 0

I was working on a class project this summer, and one of my classmates was questioning why I used something like this:

   1:  internal void Initialize()
   2:  {
   3:      ;
   4:  }

It's something programmers call an empty statement. He thought the lonely semicolon was odd, and seemed to think I shouldn't have it there. Well, here's what Microsoft says:

The empty statement consists of a single semicolon. It does nothing and can be used in places where a statement is required but no action needs to be performed.

Basically, while an empty statement literally does nothing in the compiled project, it does at least two things for me:

  1. Indicates that this is NOT a forgotten statement, but rather one I either don't need right now or that I don't intend to implement, but left in place for consistency (maybe to match a coding pattern).
  2. Allows me to wire up things like event handlers that I don't have logic for, yet.

I'm not really sure where I picked this habit up from, but I think there is nothing wrong with using empty statements, even if some people think it's wasteful...