Do you like VS Code Regions ?

The first time I saw the feature called CodeRegions was back in the 90s, the tool was  the HotDog Editor, it allows you to collapse HTML tag elements.  Now, with VS.Net we have the same feature for C# and VB.Net code. I liked it.

The first idea that comes to every developer is: "wow !!, we are going to use REGIONS to indicate the different Code Areas, like: PROPERTIES, METHODS, IMPL_INTERFACES, and so on.." so we don't need to scroll to see a specific piece of code.

But what happens when people abuse of regions? I've seen different mistakes:

  • Use regions to delimit just one line of code (and sometimes none !!)
  • Use regions to delimit functionality,  instead of Refactor it with the ExtractClass Pattern
  • Regions get unmantained as the code changes, so you get the WrongComments AntiPattern.
  • Simple classes of few lines of code becomes complex code because the regions

Another important drawback of the regions is the fact it's a VS only feature. I only write code with VS, but I use to read code with different tools and viewers that don't understand regions, like SourceInsight, HTMLConverters, or a simple copy-paste in any document.

Finally, I have decided to NotUseRegions, instead I always try to refactor the code until it transmit intention while compiles. MicroDesign. 

Clean Code That Works does not need Regions.


Comments (3)

  1. Wedgebert says:

    We have a coding standard that requires the use of a few default regions. Basically you have a region for fields, properties, methods and constructors, then duplicate them so you have Instance and Static. Any custom region we want has to nested inside of those regions.

    Finally we have to surround the class itself with a region.

    The reason for all this is our boss likes to open a file up and only see one line "Region: Classname". Then when that region is expanded you only see the major categories of stuff.

    It’s a real pain and pointless abuse of regions.

  2. Tobin Titus says:

    here here! I was a former abuser of the Code regions. I thought, for the longest time that they helped to highlight code. I used to use them to distinguish between fields, properties, constructors, etc, but then went further and used regions to hide lengthy XmlComments. After I figured out how to get my xml comments out of the code I’ve decided I like clean code much more than highly-decorated code.

  3. It’s not only for VS. IIRC, #develop has this feature and I even updated the cs.vim script at to fold the first level of regions in vim (VI iMproved), my vanilla text editor of choice.

Skip to main content