Derik Whittaker



Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at
Overuse of #Regions

Before I get started, I personally am a fan of using #regions in my code.  I think it cleans up everything, allowing me to only see what I want to see.  I also know that many of you disagree with me, and that is fine.

Here are 2 posts that voice their disapproval for regions if you are interested.

As much of a fan as i am of them, sometimes they are just waste.  Today i came across a code file that was had the following regions.  (I have changed the actual region tags to protect the innocent:)

#region Custom Methods

#region private bool MethodThatDoesSomething
private bool MethodThatDoesSomething(){}

#region private void AnotherMethodThatDoesSomething
private void AnotherMethodThatDoesSomething(){}


By putting the private methods inside it OWN region region the author has accomplished NOTHING, except making my hunt even further for the code i need to modify.  This was just total waste.

If you are like me and like regions, my guess is that it is because you believe that it better organize your code.  But you must know when enough is enough.  Please don't put individual methods inside a region that is meant to ONLY hold that method.

Till next time,

Posted 01-15-2008 7:56 AM by Derik Whittaker



Eber Irigoyen wrote re: Overuse of #Regions
on 01-15-2008 10:36 AM

it seems the developer thinks that only regions can be collapsed

Dave Schinkel wrote re: Overuse of #Regions
on 01-15-2008 11:50 AM

2 things

1) If you're gonna use regions, you better make sure your team has a standard on them.  I can't stand seeing different classes using a different structure

2) Keep them generic in nature.  Instead of lets say naming a region for example "Code to Bind Product GridView"...just name it "Binding Methods" or something

3) I agree, too many, just makes it more confusing.  Since this is OOP, regions can be divided based on areas such as Properties, Page Functions, etc.  Keep it simple such as "Constructors", "Utility Methods" etc. and use OOP terminology, not custom termonology

Dave S wrote re: Overuse of #Regions
on 01-15-2008 11:53 AM

Amazing, I've never seen something so stupidly coded:

#region private bool MethodThatDoesSomething

private bool MethodThatDoesSomething(){}


that's just like creating a method that only does one thing, calls another method which is just dumb.  Obviously whoever did that don't know how to code in the first place.  Sad but just stating a truth. wrote Overuse of #Regions
on 01-15-2008 11:55 AM

You've been kicked (a good thing) - Trackback from

Nikola Malovic wrote re: Overuse of #Regions
on 01-30-2008 5:01 PM

If separation of concerns is properly applied types in .NET are relatively speaking with small number of members/lines, so the value of regions is disputable in my opinion

I am using them ocassionally only to "group" (read hide) a bunch of helper private methods which were result of "Extract method" decomposing of complex methods.

Summarized: IMHO, one should avoid using regions and if using them at all, he should use them to hide code noise

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)