Friday, July 07, 2006

 

#region ... #endregion

#region my rant

Microsoft introduces a keyword #region ... #endregion that supposedly can be used to organize "like" codes into itsown region.

However, lately I have been encountering that it's also used as a somewhat of an excuse to have big classes. Somehow the use of #region makes it a little tolerable to have big classes.

I don't know if this is what Microsoft intends or not, but it's clearly not an appropriate solution to say the least.

The problem with big classes not only because it's not pretty to our eyesight, but there are some other basic problems with them:
1. Big classes are usually hard to test.
2. Big classes are usually error prone, because regardless of how we divide it up in regions, we still have to understand details of the class, and most humans usually comprehend things as smaller chunks better than one large chunk.
3. The use of region itself should have triggered the fact that the class might have low cohesiveness, thus they could be broken up to smaller classes.

The problems with region are:
1. It's another thing that we have to maintain to make sure things in the region are all "related", I have seen many times, that region starts out well but become "stink" over time.
2. Who's deciding what region to create, which code should go to which region, etc. This is left to each developer interpretation, should we have code review for the region ;-)

#endregion my rant

Comments: Post a Comment



<< Home

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