Wednesday, March 7, 2012

#region #endregion - You might have stinky code

Methods perform one and only one function. Methods with less than 15 lines of code makes me want to take a deep inhale. Getting a good whiff of that fresh smelling code.

Having more than 15 lines of code most likely mean you are doing more than one function. When I see these types of methods, I want to hide my nose under my t-shirt. Or maybe just pinch my nose closed.  Writing unit tests for run on methods that reach 100's of lines is nearly impossible. The maintainability of long stinky methods is low. Of course there are always exceptions, but short  methods are always my goal.

If your method has regions, you might have stinky code.

Applying the same idea to classes works also.  I really don't have a target for a class.  No magic number of methods or number of lines of code in a class. Your code is most likely stinky if you have one class in your library or application that has hundreds of methods and over 50 percent of code in your application.  Even more likely if the class is called main, or util.

Again in a class if you might have stinky code if you have regions.

Leaving #region out of your code leads to fresh smelling code.

No regions also means you don't have to remember those pesky shortcut keys to expand those regions any more.


No comments:

Post a Comment