次の方法で共有


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

  • Anonymous
    May 23, 2005
    The comment has been removed
  • Anonymous
    May 23, 2005
    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.
  • Anonymous
    May 23, 2005
    It's not only for VS. IIRC, #develop has this feature and I even updated the cs.vim script at http://vim.sourceforge.net to fold the first level of regions in vim (VI iMproved), my vanilla text editor of choice.