I suggest you ...

#region Directive Considered Harmful (was "Get rid of #region")

My informal analysis concludes that #regions are used for evil 96% of the time.

430 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    K. Scott Allen shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    Hey Scott,

    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.

    Regards,

    -Anthony D. Green, Program Manager, Visual Basic & C# Languages Team

    105 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...
      • Mario commented  ·   ·  Flag as inappropriate

        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  ·   ·  Flag as inappropriate

        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 :-)

      • Terrence commented  ·   ·  Flag as inappropriate

        #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?

      1 2 3 4 6 Next →

      Feedback and Knowledge Base