#region Directive Considered Harmful (was "Get rid of #region")
My informal analysis concludes that #regions are used for evil 96% of the time.
Thanks for taking the time to make this suggestion. I think every programmer has one or more features in any language which they just hate because they’ve been abused by someone else. I’ve renamed this post to capture that immortalized hatred all programmers share for such evil constructs!
Having said that, #regions do have valid use 4% of the time to someone (arguably grouping interface implementations within a class?) and even if there weren’t it’s really far too late to remove them (even if we thought they were evil, which we don’t). It simply wouldn’t be responsible to the millions of developers out there who might have #region directives in their code today either intentionally or having inherited them from other developers (at least some of which have passionately argued on this thread below) to break that code now without a pretty darn good reason. As a rule, generally speaking it’s somewhere the C# language design team just doesn’t go.
Luckily we have tools like StyleCop and one day “Roslyn” which can be leveraged to enforce our dreams of code purity, at least within our own spheres of influence.
-Anthony D. Green, Program Manager, Visual Basic & C# Languages Team
Some like #regions and some don't. Some think they are distracting, while some think they are organizing.
Why remove something you don't need to use, but is used by some who find it useful? I think you can use #regions and still keep it neat without the need to refactor code.
For me it's a great way, for example, to keep apart event methods from other methods. That way I can find methods faster and it works best for me (saying that we are different and what's best for me is not necessarily best for another).
Ken Mullins commented
Possibly inside blocks of code (C# not VB) however multiple methods enclosed in #regions makes great sence. IE Properties, Constructors, Mehtods - Private, Methods - Public etc. Works for me and keeps the code space organised :-)
Plain and simple, #regions are a code smell for large blocks code that need to be refactored - http://en.wikipedia.org/wiki/Code_refactoring. They are also distracting, unnecessary noise in a code base.
#regions are a great way of minimizing large sections of code. When I minimize my code I see 3-4 regions. Properties and contstuctor, Public Methods, private methods....etc.
Or in my controller, ABCViewMethods, DEFViewMethods.
Why get rid of them?
Why is that?
What's evil and what's the 4% good with #regions?