I suggest you ...

Get rid of #region

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

381 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    K. Scott AllenK. Scott Allen shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    86 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Akash KavaAkash Kava commented  ·   ·  Flag as inappropriate

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

        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.

      • pvittpvitt commented  ·   ·  Flag as inappropriate

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

        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?

      • KenKen commented  ·   ·  Flag as inappropriate

        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.

      • DajoDajo commented  ·   ·  Flag as inappropriate

        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.

      • jonathanjonathan commented  ·   ·  Flag as inappropriate

        whats wrong with #region? its makes my class's nice and neat :)

      • JMCF125JMCF125 commented  ·   ·  Flag as inappropriate

        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?

      • JMCF125JMCF125 commented  ·   ·  Flag as inappropriate

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

      • abatishchevabatishchev commented  ·   ·  Flag as inappropriate

        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!

      • AndrewAndrew commented  ·   ·  Flag as inappropriate

        "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

      • BrettBrett commented  ·   ·  Flag as inappropriate

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

      • John CronanJohn Cronan commented  ·   ·  Flag as inappropriate

        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...

      ← Previous 1 3 4 5

      Feedback and Knowledge Base