Geeks With Blogs
Darren Fieldhouse

I’m not a big fan of #region, I use it occasionally but generally try to avoid it. It’s always frustrating to open a code file and be presented with nothing but collapsed regions – sure, it looks neat (and lets face, more than a few programmers are a little OCD) but I want to see the code, that’s why I opened the file in the first place!

Don’t worry, I’m not going off on a rant, I just want to direct you to a much more level headed explanation of The Problem With Code Folding. I couldn’t agree more.

Posted on Friday, May 21, 2010 6:03 AM | Back to top

Comments on this post: The evils of #region

# re: The evils of #region
Requesting Gravatar...
I do not like regions with names like "Public Methods" or "Private Instance Fields" because the names of these regions are not useful. However, I do use them to separate code into groups of functionality.

For instance, I might have a region called "Account" containing all of the methods, properties and fields that are used to operate on an Account. Then I might have other regions called "User", "Connection", etc...

This works out pretty well and most people that look at our code can figure out what is going on pretty quickly because we also put the regions in an order that makes sense.
Left by WayneB on May 22, 2010 9:52 PM

# re: The evils of #region
Requesting Gravatar...
Hi Wayne,

Your approach is certainly much better than folding up "public methods", "private methods" etc. but what happens when a junior dev put a method in the wrong region? In a scenario like yours I would strive to split the class into smaller classes rather than divide it up into #regions. If you are following the SOLID principles then S is for Single Responsibility – each class should only be responsible for one thing (or have one reason to change) so each region should be a class.
Left by Darren Fieldhouse on May 23, 2010 4:32 AM

Your comment:
 (will show your gravatar)

Copyright © DarrenFieldhouse | Powered by: