Get rid of #region
My informal analysis concludes that #regions are used for evil 96% of the time.
86 comments
-
Marcel
commented
380 votes??? Why not get rid of the remarks ?
-
Akash Kava
commented
Get better programmers in your company, we have good programmers and they use regions nicely. It is great feature and we wish it was there in every language.
-
Corey Murtagh
commented
This is a completely frivolous request that has nothing to do with C# as a language.
#region is a purely decorative directive that is used only to control folding within the development environment. Removing all #region and #endregion directives in a source file will not change the generated code, except as far as changing the line numbers in debug information.
How developers choose to use regions is up to them, and has nothing to do with the language itself.
-
Jeroen van Warmerdam
commented
I wish I could down-vote a suggestion...
-
pvitt
commented
When regions are misused, don't eliminate regions. Instead empowering your develpers to use them the right way seems to be the more constructive solution.
-
Vince Panuccio
commented
The problem with regions is that they are named in a way that makes sense to the developer who initially wrote the code. I often come across regions like "Common methods" or "Helper functions". It's bloody madness and when you confront them, they look at you like it should be obvious.
It's hard to find and read code with regions.
The only regions I prefer are ones that make sense. "Constructors" is a good one, that's obvious. Or "Static Properties" is another.
If you don't like regions, use CTRL M + CTRL L to expand everything. If you're that against them, have a commit hook in your SCM that disallows them.
Now can we please stop complaining over stupid requests like this?
-
HandsomeMark
commented
Keep #regions, please and thank you.
-
Ken
commented
My use of words doesn't mean that I've flagged this suggestion, but it's very inappropriate!
#regions can be useful, and you did not specify any concrete reason to why it should be removed.All you can say is "I'm not going to use #regions!" and we'll respond with "Good for you!".
The ones that do enjoy them shouldn't have to be condemned to live on without them only because you don't like it. -
Zbigniew Michalak
commented
Regions are very useful!
-
Dajo
commented
Finally found a beneficial use for regions. I now try to group class member together based on whether they best fit a creational, structural or behavioral concern. Basically the 3 categories identified in GoF patterns. It a usual way of highlighting methods that have more than a single concern and might benefit from a little refactoriing.
So whilst I share your pain when inheriting other people's code they do now serve a useful purpose for me.
-
jonathan
commented
whats wrong with #region? its makes my class's nice and neat :)
-
José Luis
commented
I'm giving you -323 votes :-)
I love #region -
JMCF125 commented
I think my last comment was too short. I can't believe this has 323 votes. Do you want to prohibit cars as well because crazy people may intencionally crash them?
-
JMCF125 commented
#region is only a problem if you make it so. Used appropriately, they can be a great help. Too bad we can't vote down.
-
mjcarrabine
commented
I love #region too, dont' get rid of it.
-
abatishchev commented
Why don't nest regions? It's absolutely legal. For instance, "Inner classes" then "Properties" in each,
Don't use regions inside methods' body, that what I definitely support. Refactor and extract instead! -
Andrew
commented
"My informal analysis concludes that #regions are used for evil 96%"
-- Then you don't know how to use them...1) Don't nest reigns.
2) Have a clear understood usage pattern for you projects.I only use regions in my projects for grouping the following categories in order from top to bottom in a class object - "Properties, Constructors, Operators and Methods"
Or I use regions for other very special cases. They are misused yes, but only by unorganized coders O_o -
Brett
commented
#Region is not a problem, it is the way developers are educated to use them. When used to break up and clarify areas of work they are fine. I use them in MVVM Vm's to isolate Commands, Command Handlers, Bound Properties etc. When regions are called Public Methods, Private Methods is when they add no value to the code. Use seperation of concerns effectively and don't copy what you saw in some text books, and above all Think before you Region, if it add no clarity do not use it.
-
Justin Chase
commented
For the dissenters of this suggestion, please read:
http://www.codinghorror.com/blog/2008/07/the-problem-with-code-folding.html -
John Cronan
commented
Having eradicated smallpox, humanity's next major targets should be malaria and regions.
A once-great idea with which the developer community clearly cannot be trusted...