Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Regions: Love or Hate

Regions: Love or Hate

Scheduled Pinned Locked Moved The Lounge
csharpcssvisual-studiocollaborationhelp
93 Posts 63 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Dave Kerr

    Just snorted tea all over my desk with that one

    W Offline
    W Offline
    W Balboos GHB
    wrote on last edited by
    #41

    You should not be surprised to learn that you've just made my day.

    "The difference between genius and stupidity is that genius has its limits." - Albert Einstein

    "As far as we know, our computer has never had an undetected error." - Weisert

    "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010

    1 Reply Last reply
    0
    • K Keith Barrow

      Used to like, now dislike: Used to like and used them to tidy up "sections" of classes (e.g. fields, properties, methods) now I've come round to the opinion that is just hides code. Too often they hide incorrect class structure and poor general design. The worst offenders in this case are inside methods where a region is used to hide what should be refactored into private methods in some poorly written god-method. I've seeen them used to hide Data Access stuff in an object model which should have been a whole different architectural layer and entire "classes" within a god-class.

      Sort of a cross between Lawrence of Arabia and Dilbert.[^]
      -Or-
      A Dead ringer for Kate Winslett[^]

      A Offline
      A Offline
      AspDotNetDev
      wrote on last edited by
      #42

      Keith Barrow wrote:

      I've seeen them used to hide Data Access stuff in an object model which should have been a whole different architectural layer and entire "classes" within a god-class.

      Guilty.

      Martin Fowler wrote:

      Any fool can write code that a computer can understand. Good programmers write code that humans can understand.

      1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Slacker007 wrote:

        your team needs to ALL be on the same sheet of music

        Oh yes! Nothing worse than one idiot individual who insists on K&R bracket format when everyone else has got an IQ bigger than their shoe size moved on to a more readable style.

        Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."

        Q Offline
        Q Offline
        QuiJohn
        wrote on last edited by
        #43

        OriginalGriff wrote:

        Oh yes! Nothing worse than one idiot individual who insists on K&R bracket format when everyone else has got an IQ bigger than their shoe size moved on to a more readable style.

        Hey now, a lot of us started C programming with K&R sitting next to our keyboards. Sure, maybe they did it to save on the number of published pages, but it was as natural as breathing. After many years I finally realized it looked like crap though, and forced myself to change ;)

        OriginalGriffO 1 Reply Last reply
        0
        • R realJSOP

          I like regions to a point. I think they would be more useful if we could set their background color to something other than the white space color.

          ".45 ACP - because shooting twice is just silly" - JSOP, 2010
          -----
          You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
          -----
          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

          Q Offline
          Q Offline
          QuiJohn
          wrote on last edited by
          #44

          John Simmons / outlaw programmer wrote:

          I think they would be more useful if we could set their background color to something other than the white space color.

          That is an outstanding idea. I never, ever use them right now. But color coded regions would make me feel not as bad about those 500 line functions. (They're not my fault! Entirely...)

          1 Reply Last reply
          0
          • Q QuiJohn

            OriginalGriff wrote:

            Oh yes! Nothing worse than one idiot individual who insists on K&R bracket format when everyone else has got an IQ bigger than their shoe size moved on to a more readable style.

            Hey now, a lot of us started C programming with K&R sitting next to our keyboards. Sure, maybe they did it to save on the number of published pages, but it was as natural as breathing. After many years I finally realized it looked like crap though, and forced myself to change ;)

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #45

            I did too - after a Instruction Set one week course - but I hated it then, and it caused so many problems because the indentation looked right but didn't match the brackets that I went over to "indented bracket" and have never look back. You still get some people who will change all code they find back to it though... X|

            Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              I wasn't sure until I started using them to group related items in the same file: Fields Properties Constructors Event handlers Public properties Private properties Now I find it reduces the clutter, and lets you see what you are interested in, without being distracted by irrelevancies. So much so that I modified the VS default class (and so forth) files to include them as standard. There is a Tip/Trick about it here: Adding your items to Visual Studio default files[^]

              Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."

              D Offline
              D Offline
              Dan Neely
              wrote on last edited by
              #46

              +5 That's similar to how I generally organize my regions.

              Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

              1 Reply Last reply
              0
              • D Dave Kerr

                I used to love regions, stuck them everywhere in my code. Now I hate them, each member of our team uses them differently. What's the public opinion - are regions good or bad? Would they be better if they were REALLY big in Visual Studio? I find that I'm squinting to find the little buggers, if they were much more obvious I might get lost less...

                M Offline
                M Offline
                Marc Clifton
                wrote on last edited by
                #47

                Regions is one of those things that sounds like a great idea but sucks in actual use. Why not just set your editor to always expand all regions? No squinting necessary. :) Marc

                My Blog

                1 Reply Last reply
                0
                • D Dave Kerr

                  I used to love regions, stuck them everywhere in my code. Now I hate them, each member of our team uses them differently. What's the public opinion - are regions good or bad? Would they be better if they were REALLY big in Visual Studio? I find that I'm squinting to find the little buggers, if they were much more obvious I might get lost less...

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #48

                  Meh, they only work in an IDE, so I don't generally use them. However, I do use them for some code with a bunch of overloads that I intend to share with others -- here are the Foo methods, here are the Bar methods, etc; or to collapse error-handling so the reader can more easily see the logic of the method. However, I'm of the opinion that very large classes should be broken into separate files (using a partial class) rather than regions -- for instance a Data Access Layer may have separate files for the various methods that act on the various files of the database.

                  1 Reply Last reply
                  0
                  • D Dave Kerr

                    I used to love regions, stuck them everywhere in my code. Now I hate them, each member of our team uses them differently. What's the public opinion - are regions good or bad? Would they be better if they were REALLY big in Visual Studio? I find that I'm squinting to find the little buggers, if they were much more obvious I might get lost less...

                    V Offline
                    V Offline
                    Vark111
                    wrote on last edited by
                    #49

                    I only use them in two cases: - private nested classes - to wrap interface implementation *only* if the class in question implements multiple interfaces. I used to use them to wrap properties, fields, methods, etc... but I've moved away from that.

                    1 Reply Last reply
                    0
                    • D Dave Kerr

                      I used to love regions, stuck them everywhere in my code. Now I hate them, each member of our team uses them differently. What's the public opinion - are regions good or bad? Would they be better if they were REALLY big in Visual Studio? I find that I'm squinting to find the little buggers, if they were much more obvious I might get lost less...

                      S Offline
                      S Offline
                      Single Step Debugger
                      wrote on last edited by
                      #50

                      With the outlining working so well I find regions rather distracting than useful. Also I think it’s a personal thing; the people who are pedantic how their code looks, those type of people who would use lambdas and wright a huge comment blocks for every method probably loves the regions. Developers who are more concern about readability and usability of their code probably use the regions very rarely if at all.

                      There is only one Ashley Judd and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.

                      1 Reply Last reply
                      0
                      • OriginalGriffO OriginalGriff

                        I wasn't sure until I started using them to group related items in the same file: Fields Properties Constructors Event handlers Public properties Private properties Now I find it reduces the clutter, and lets you see what you are interested in, without being distracted by irrelevancies. So much so that I modified the VS default class (and so forth) files to include them as standard. There is a Tip/Trick about it here: Adding your items to Visual Studio default files[^]

                        Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #51

                        Perhaps also a region for destructors/finalizers/dispose where needed?

                        "Dark the dark side is. Very dark..." - Yoda ---
                        "Shut up, Yoda, and just make yourself another toast." - Obi Wan Kenobi

                        1 Reply Last reply
                        0
                        • D Dave Kerr

                          I used to love regions, stuck them everywhere in my code. Now I hate them, each member of our team uses them differently. What's the public opinion - are regions good or bad? Would they be better if they were REALLY big in Visual Studio? I find that I'm squinting to find the little buggers, if they were much more obvious I might get lost less...

                          P Offline
                          P Offline
                          peterchen
                          wrote on last edited by
                          #52

                          Good when not abused. In a team, agree on / decree a coding standard, and have the balls to enforce it. -------- I wished we finally moved away from this text file thing and moved to a more entity-centric editing, keepign the text thing only for backward compatibility.

                          FILETIME to time_t
                          | FoldWithUs! | sighist | WhoIncludes - Analyzing C++ include file hierarchy

                          1 Reply Last reply
                          0
                          • OriginalGriffO OriginalGriff

                            Slacker007 wrote:

                            your team needs to ALL be on the same sheet of music

                            Oh yes! Nothing worse than one idiot individual who insists on K&R bracket format when everyone else has got an IQ bigger than their shoe size moved on to a more readable style.

                            Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."

                            B Offline
                            B Offline
                            BobJanova
                            wrote on last edited by
                            #53

                            I like same-line braces and find it more readable (in that you can see more than 2 lines of actual code at once). You may not like it but calling anyone who does an idiot is rather unfair.

                            1 Reply Last reply
                            0
                            • D Dave Kerr

                              I used to love regions, stuck them everywhere in my code. Now I hate them, each member of our team uses them differently. What's the public opinion - are regions good or bad? Would they be better if they were REALLY big in Visual Studio? I find that I'm squinting to find the little buggers, if they were much more obvious I might get lost less...

                              B Offline
                              B Offline
                              BobJanova
                              wrote on last edited by
                              #54

                              I hate them. They are a way of making a file which is too complicated and should be split up appear not to be. If you think you need them, consider whether some of that code is actually necessary at all, or in the right place.

                              D 1 Reply Last reply
                              0
                              • B BobJanova

                                I hate them. They are a way of making a file which is too complicated and should be split up appear not to be. If you think you need them, consider whether some of that code is actually necessary at all, or in the right place.

                                D Offline
                                D Offline
                                Dan Neely
                                wrote on last edited by
                                #55

                                What do you consider the too complicated and need split threshold to be? IMO regions start being useful in keeping stuff organized well before that point.

                                Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                                B 1 Reply Last reply
                                0
                                • D Dan Neely

                                  What do you consider the too complicated and need split threshold to be? IMO regions start being useful in keeping stuff organized well before that point.

                                  Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                                  B Offline
                                  B Offline
                                  BobJanova
                                  wrote on last edited by
                                  #56

                                  As soon as you can't navigate the file (in your mind or using something like the tree view which is in most IDEs showing you the structure) any more. That's obviously very subjective (and depends on the domain) but in general somewhere around 500-1000 lines.

                                  D 1 Reply Last reply
                                  0
                                  • B BobJanova

                                    As soon as you can't navigate the file (in your mind or using something like the tree view which is in most IDEs showing you the structure) any more. That's obviously very subjective (and depends on the domain) but in general somewhere around 500-1000 lines.

                                    D Offline
                                    D Offline
                                    Dan Neely
                                    wrote on last edited by
                                    #57

                                    I've never used the IDE treeviews for within classes; showing them and the one for files/projects either hogs too much space or requires swapping between them all the time adding more annoyance than it's worth. Also, even with icons globbing everything into a class into a single flat list has never seemed logical to me. A large part of what I use regions for is clumping similar items together (similar to OriginalGriff's setup[^]). With that in place I find classes generally remain manageable until around 1500 lines. The only time this is often an issue is with complex UI forms; where I've yet to find a good balance between classes getting bloated or where a specific feature is in a pile of custom controls only used on a single dialog.

                                    Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                                    1 Reply Last reply
                                    0
                                    • D Dave Kerr

                                      I used to love regions, stuck them everywhere in my code. Now I hate them, each member of our team uses them differently. What's the public opinion - are regions good or bad? Would they be better if they were REALLY big in Visual Studio? I find that I'm squinting to find the little buggers, if they were much more obvious I might get lost less...

                                      D Offline
                                      D Offline
                                      dazfuller
                                      wrote on last edited by
                                      #58

                                      I have a love/hate relationship with regions. Personally I use them for breaking a code file into sections, so Fields, Properties, Public Methods etc... Now that I don't mind as I can still find things quite easily, I'm sure others might disagree but it works for me. What I hate is when developers put them around every method! Even worse is when they only use the method name instead of the whole signature, for example

                                      #region MyMethod

                                      public int MyMethod(int a, int b) { ... }

                                      #endregion

                                      #region MyMethod

                                      public int MyMethod(int a, int b, string c) { ... }

                                      #endregion

                                      Which one is it that I need to look at? And what does this add as I can collapse the methods anyway! Seriously, if you do this then you should have your keyboard taken away from you until you know better!

                                      1 Reply Last reply
                                      0
                                      • D Dave Kerr

                                        I used to love regions, stuck them everywhere in my code. Now I hate them, each member of our team uses them differently. What's the public opinion - are regions good or bad? Would they be better if they were REALLY big in Visual Studio? I find that I'm squinting to find the little buggers, if they were much more obvious I might get lost less...

                                        S Offline
                                        S Offline
                                        SimonRigby
                                        wrote on last edited by
                                        #59

                                        Dave Kerr wrote:

                                        Now I hate them, each member of our team uses them differently.

                                        I think that's the issue right there .. its not regions that's the problem .. its inconsistent use. You could say the same for any tool/practice. I use them to group things away that I don't need to see, like private members etc, and I use them consistently for this reason.

                                        The only thing unpredictable about me is just how predictable I'm going to be.

                                        1 Reply Last reply
                                        0
                                        • M Marcus_2

                                          Good, if used with some sense.

                                          B Offline
                                          B Offline
                                          Brad Stiles
                                          wrote on last edited by
                                          #60

                                          Marcus_2 wrote:

                                          Good, if used with some sense.

                                          You mean, like almost everything else ever done in programming? :)

                                          Currently reading: "Swords and Deviltry", by Fritz Leiber

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups