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

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

    R Offline
    R Offline
    Remi BOURGAREL
    wrote on last edited by
    #61

    I always say : when you use region, just create another class ! It's useful only for generated code (like proxy class for web services)

    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
      BrianPayne
      wrote on last edited by
      #62

      I LOVE regions, but only on a structured, limited basis. They are helpful to organize the class, but can get unruly if overused. I stick to several standard regions and alphabetize my methods, properties, etc, so that everything is easy to find. - Catalyst

      1 Reply Last reply
      0
      • F Firo Atrum Ventus

        I've seen regions being abused (hiding shitty code to make it look clean), overused (why would you keep a method in a region?) and underused (as in, WTF? why would you hide all your code in a region titled "main process"). So I can safely say "I.HATE.THAT.SH*T!"

        Excuse me for my improper grammar and typos. It's because English is my primary language, not my first language. My first languages are C# and Java. VB, ASP, JS, PHP and SQL are my second language. Indonesian came as my third language. My fourth language? I'm still creating it, I'll let you know when it's done! :-D

        T Offline
        T Offline
        TNCaver
        wrote on last edited by
        #63

        It seems to me that you really don't hate regions, you just hate how they've been misused.

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

          8 Offline
          8 Offline
          8xFather
          wrote on last edited by
          #64

          I liked the idea but didn't use them very often because they didn't stand out when collapsed. After changing the “Collapsed Text” to orange in the options I use them a lot. Tools/Options/Environment/Fonts and Colors/Collapsed Text/Item foreground

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

            T Offline
            T Offline
            TNCaver
            wrote on last edited by
            #65

            I find them useful to separate true regions in the code, i.e., constructors, private properties, public properties, private methods and public methods. They are useful especially in code-behind pages with a lot of code that make for a lot of scrolling. When I collapse the code page to definitions, they are all you see between the class definition and Namespace declarations, making it easy to expand the region I'm looking for to view, edit or add to. Most of the comments I've seen here that oppose them seem to direct their hatred at how they are (mis)used, but don't really say why regions are in themselves bad. That's kind of like hating pencils because they can be used to write bad English. :)

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

              N Offline
              N Offline
              Naruki 0
              wrote on last edited by
              #66

              idiots people who like stupid space-wasting, conceptually-disorganized styles like Allman. But I guess the use of inferior editors that are incapable of brace matching, as well as dysfunctional eyes that cannot scan up-/downward to matching indents, are all factors in why they would give up as real developers need to use such a style. That, or they just really, really, really love Microsoft. 1TBS or GTFO

              Narf.

              OriginalGriffO 1 Reply Last reply
              0
              • M Marcus_2

                Good, if used with some sense.

                S Offline
                S Offline
                spencepk
                wrote on last edited by
                #67

                This is what I call abuse/overuse. It makes my eyes roll back in my head when I see this crap, comments would've been more than sufficient.

                        foreach (DataRow currentRow in sortedTable.Table.Rows) {
                            #region Load Data and set defaults
                            creditCardNumber = currentRow\["CCNUMBER"\].ToString();
                            cardHolder = currentRow\["CARDHOLDER"\].ToString();
                            employeeId = currentRow\["EMPLCODE"\].ToString();
                            deptNumber = currentRow\["DEPTCODE"\].ToString();
                            accountNumber = currentRow\["GLCODE"\].ToString();
                            expElemNumber = currentRow\["EXPELEM"\].ToString();
                            fullRecord = currentRow\["FULLRECORD"\].ToString();
                            isValidDept = true;
                            isValidAcct = true;
                            #endregion
                            #region If Company Credit Card, don't process
                            if (creditCardNumber == companyCard) {
                                Trace.WriteLineIf(tron, "\[VERIFICATION\] Skipping Company Credit Card... ");
                                continue;
                            }
                            else {
                                this.statusReport.Text = "Verifying " + creditCardNumber + "...";
                                this.rtbStatus.Text += "Verifying " + creditCardNumber + " \[" + cardHolder.Trim() + "\]...\\t";
                                Trace.WriteLineIf(tron, "\[VERIFICATION\] Verifying Credit Card # : " + creditCardNumber);
                                email\_er.Write("Credit Card Number: " + creditCardNumber + " for Card Holder: " + cardHolder.Trim() + "...");
                            }
                            #endregion
                            #region Address Employee #, Dept #, Account #, and Expense Element
                            if (employeeId.Trim().Length != 4) {
                                employeeId = employeeId.PadLeft(4, '0');
                            }
                            if (deptNumber.Trim().Length != 4) {
                                deptNumber = deptNumber.PadLeft(4, '0');
                            }
                            if (accountNumber.Trim().Length != 7) {
                                accountNumber = accountNumber.PadLeft(7, '0');
                            }
                            if (expElemNumber.Trim().Length != 2) {
                                expElemNumber = expElemNumber.PadLeft(2, '0');
                            }
                            #endregion
                            #region Verify Deptartment Number from BoA File
                            try {
                                isValidDept = query.isValidDepartment(deptNumber);
                                if (!isValidDept) Trace.WriteLineIf(tron, "\[VERIFICATION\] Bank of America Department is in
                
                T K K K K 5 Replies 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...

                  F Offline
                  F Offline
                  Fernando A Gomez F
                  wrote on last edited by
                  #68

                  I don't use them. I use Visual Studio's class explorer to navigate to the desired member, so don't need them. I don't mind if anybody else uses them though...

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

                    J Offline
                    J Offline
                    John Boyett
                    wrote on last edited by
                    #69

                    That makes a lot of sense. I might try using them that way.

                    1 Reply Last reply
                    0
                    • N Naruki 0

                      idiots people who like stupid space-wasting, conceptually-disorganized styles like Allman. But I guess the use of inferior editors that are incapable of brace matching, as well as dysfunctional eyes that cannot scan up-/downward to matching indents, are all factors in why they would give up as real developers need to use such a style. That, or they just really, really, really love Microsoft. 1TBS or GTFO

                      Narf.

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

                      Wouldn't know - I use Whitesmiths style. :-D

                      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

                      N 1 Reply Last reply
                      0
                      • OriginalGriffO OriginalGriff

                        Wouldn't know - I use Whitesmiths style. :-D

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

                        N Offline
                        N Offline
                        Naruki 0
                        wrote on last edited by
                        #71

                        If anything, that is an even more retarded differently-abled variant of Allman. You have my sympathies. Hopefully, you are functional enough to be allowed to live a [mostly] normal adult life.

                        Narf.

                        1 Reply Last reply
                        0
                        • S spencepk

                          This is what I call abuse/overuse. It makes my eyes roll back in my head when I see this crap, comments would've been more than sufficient.

                                  foreach (DataRow currentRow in sortedTable.Table.Rows) {
                                      #region Load Data and set defaults
                                      creditCardNumber = currentRow\["CCNUMBER"\].ToString();
                                      cardHolder = currentRow\["CARDHOLDER"\].ToString();
                                      employeeId = currentRow\["EMPLCODE"\].ToString();
                                      deptNumber = currentRow\["DEPTCODE"\].ToString();
                                      accountNumber = currentRow\["GLCODE"\].ToString();
                                      expElemNumber = currentRow\["EXPELEM"\].ToString();
                                      fullRecord = currentRow\["FULLRECORD"\].ToString();
                                      isValidDept = true;
                                      isValidAcct = true;
                                      #endregion
                                      #region If Company Credit Card, don't process
                                      if (creditCardNumber == companyCard) {
                                          Trace.WriteLineIf(tron, "\[VERIFICATION\] Skipping Company Credit Card... ");
                                          continue;
                                      }
                                      else {
                                          this.statusReport.Text = "Verifying " + creditCardNumber + "...";
                                          this.rtbStatus.Text += "Verifying " + creditCardNumber + " \[" + cardHolder.Trim() + "\]...\\t";
                                          Trace.WriteLineIf(tron, "\[VERIFICATION\] Verifying Credit Card # : " + creditCardNumber);
                                          email\_er.Write("Credit Card Number: " + creditCardNumber + " for Card Holder: " + cardHolder.Trim() + "...");
                                      }
                                      #endregion
                                      #region Address Employee #, Dept #, Account #, and Expense Element
                                      if (employeeId.Trim().Length != 4) {
                                          employeeId = employeeId.PadLeft(4, '0');
                                      }
                                      if (deptNumber.Trim().Length != 4) {
                                          deptNumber = deptNumber.PadLeft(4, '0');
                                      }
                                      if (accountNumber.Trim().Length != 7) {
                                          accountNumber = accountNumber.PadLeft(7, '0');
                                      }
                                      if (expElemNumber.Trim().Length != 2) {
                                          expElemNumber = expElemNumber.PadLeft(2, '0');
                                      }
                                      #endregion
                                      #region Verify Deptartment Number from BoA File
                                      try {
                                          isValidDept = query.isValidDepartment(deptNumber);
                                          if (!isValidDept) Trace.WriteLineIf(tron, "\[VERIFICATION\] Bank of America Department is in
                          
                          T Offline
                          T Offline
                          TNCaver
                          wrote on last edited by
                          #72

                          That is a horrible misuse. Regions should never be used inside a code block, IMO.

                          1 Reply Last reply
                          0
                          • S spencepk

                            This is what I call abuse/overuse. It makes my eyes roll back in my head when I see this crap, comments would've been more than sufficient.

                                    foreach (DataRow currentRow in sortedTable.Table.Rows) {
                                        #region Load Data and set defaults
                                        creditCardNumber = currentRow\["CCNUMBER"\].ToString();
                                        cardHolder = currentRow\["CARDHOLDER"\].ToString();
                                        employeeId = currentRow\["EMPLCODE"\].ToString();
                                        deptNumber = currentRow\["DEPTCODE"\].ToString();
                                        accountNumber = currentRow\["GLCODE"\].ToString();
                                        expElemNumber = currentRow\["EXPELEM"\].ToString();
                                        fullRecord = currentRow\["FULLRECORD"\].ToString();
                                        isValidDept = true;
                                        isValidAcct = true;
                                        #endregion
                                        #region If Company Credit Card, don't process
                                        if (creditCardNumber == companyCard) {
                                            Trace.WriteLineIf(tron, "\[VERIFICATION\] Skipping Company Credit Card... ");
                                            continue;
                                        }
                                        else {
                                            this.statusReport.Text = "Verifying " + creditCardNumber + "...";
                                            this.rtbStatus.Text += "Verifying " + creditCardNumber + " \[" + cardHolder.Trim() + "\]...\\t";
                                            Trace.WriteLineIf(tron, "\[VERIFICATION\] Verifying Credit Card # : " + creditCardNumber);
                                            email\_er.Write("Credit Card Number: " + creditCardNumber + " for Card Holder: " + cardHolder.Trim() + "...");
                                        }
                                        #endregion
                                        #region Address Employee #, Dept #, Account #, and Expense Element
                                        if (employeeId.Trim().Length != 4) {
                                            employeeId = employeeId.PadLeft(4, '0');
                                        }
                                        if (deptNumber.Trim().Length != 4) {
                                            deptNumber = deptNumber.PadLeft(4, '0');
                                        }
                                        if (accountNumber.Trim().Length != 7) {
                                            accountNumber = accountNumber.PadLeft(7, '0');
                                        }
                                        if (expElemNumber.Trim().Length != 2) {
                                            expElemNumber = expElemNumber.PadLeft(2, '0');
                                        }
                                        #endregion
                                        #region Verify Deptartment Number from BoA File
                                        try {
                                            isValidDept = query.isValidDepartment(deptNumber);
                                            if (!isValidDept) Trace.WriteLineIf(tron, "\[VERIFICATION\] Bank of America Department is in
                            
                            K Offline
                            K Offline
                            Kabwla Phone
                            wrote on last edited by
                            #73

                            I think this is a good example of good usage. The advantage a region has over a comment is that a region can signal the end of your logical block. With a comment you would have to asume that the comment is valid until the next comment. And as you know, assumtion makes an ... out of u and me.

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

                              A Offline
                              A Offline
                              Alan Burkhart
                              wrote on last edited by
                              #74

                              I generally group code blocks in regions according to purpose. The file menu and edit menu each gets its own region, and printing, if the project does any printing. It helps me stay organized and makes various blocks of code easier to find.

                              XAlan Burkhart

                              1 Reply Last reply
                              0
                              • S spencepk

                                This is what I call abuse/overuse. It makes my eyes roll back in my head when I see this crap, comments would've been more than sufficient.

                                        foreach (DataRow currentRow in sortedTable.Table.Rows) {
                                            #region Load Data and set defaults
                                            creditCardNumber = currentRow\["CCNUMBER"\].ToString();
                                            cardHolder = currentRow\["CARDHOLDER"\].ToString();
                                            employeeId = currentRow\["EMPLCODE"\].ToString();
                                            deptNumber = currentRow\["DEPTCODE"\].ToString();
                                            accountNumber = currentRow\["GLCODE"\].ToString();
                                            expElemNumber = currentRow\["EXPELEM"\].ToString();
                                            fullRecord = currentRow\["FULLRECORD"\].ToString();
                                            isValidDept = true;
                                            isValidAcct = true;
                                            #endregion
                                            #region If Company Credit Card, don't process
                                            if (creditCardNumber == companyCard) {
                                                Trace.WriteLineIf(tron, "\[VERIFICATION\] Skipping Company Credit Card... ");
                                                continue;
                                            }
                                            else {
                                                this.statusReport.Text = "Verifying " + creditCardNumber + "...";
                                                this.rtbStatus.Text += "Verifying " + creditCardNumber + " \[" + cardHolder.Trim() + "\]...\\t";
                                                Trace.WriteLineIf(tron, "\[VERIFICATION\] Verifying Credit Card # : " + creditCardNumber);
                                                email\_er.Write("Credit Card Number: " + creditCardNumber + " for Card Holder: " + cardHolder.Trim() + "...");
                                            }
                                            #endregion
                                            #region Address Employee #, Dept #, Account #, and Expense Element
                                            if (employeeId.Trim().Length != 4) {
                                                employeeId = employeeId.PadLeft(4, '0');
                                            }
                                            if (deptNumber.Trim().Length != 4) {
                                                deptNumber = deptNumber.PadLeft(4, '0');
                                            }
                                            if (accountNumber.Trim().Length != 7) {
                                                accountNumber = accountNumber.PadLeft(7, '0');
                                            }
                                            if (expElemNumber.Trim().Length != 2) {
                                                expElemNumber = expElemNumber.PadLeft(2, '0');
                                            }
                                            #endregion
                                            #region Verify Deptartment Number from BoA File
                                            try {
                                                isValidDept = query.isValidDepartment(deptNumber);
                                                if (!isValidDept) Trace.WriteLineIf(tron, "\[VERIFICATION\] Bank of America Department is in
                                
                                K Offline
                                K Offline
                                kp_brown
                                wrote on last edited by
                                #75

                                That. Is. Insane.

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

                                  S Offline
                                  S Offline
                                  ScottK7
                                  wrote on last edited by
                                  #76

                                  Having spent the last 10-15 minutes learning more than I ever knew, cared to know, or ever dreamed there was to know, about the names (people waste their lives inventing names for this stuff???) and histories of these various indentation styles, I now feel my brain has been eternally and irrevocably damaged for the effort. Of all the 15 minute spans of my life that have gone to waste, I believe this one will be lamented the most. And, sorry, have to agree with the last poster about your choice of styles. :)

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

                                    F Offline
                                    F Offline
                                    Fabio Franco
                                    wrote on last edited by
                                    #77

                                    I find them useful to separate different regions inside a big class, like fields, properties, methods and constructors

                                    "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

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

                                      K Offline
                                      K Offline
                                      KSig
                                      wrote on last edited by
                                      #78

                                      Place the public stuff first. That is where the story of your class starts

                                      OriginalGriffO 1 Reply Last reply
                                      0
                                      • K Kabwla Phone

                                        I think this is a good example of good usage. The advantage a region has over a comment is that a region can signal the end of your logical block. With a comment you would have to asume that the comment is valid until the next comment. And as you know, assumtion makes an ... out of u and me.

                                        M Offline
                                        M Offline
                                        Morry1337
                                        wrote on last edited by
                                        #79

                                        That was a horrible, horrible block of code. The regions dont fix that. Logical groups should be different methods not regions. We use regions around Constants & Fields and Ctors and Dtors. And this is done automagicly by our tooling. (ReSharper + Stylecop) Other than that I cant think of anywhere else I would want to use them.

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

                                          G Offline
                                          G Offline
                                          GlobX
                                          wrote on last edited by
                                          #80

                                          I LOVE regions. If I really think about it though, it's more a side-effect of the regions than the regions themselves. I usually have a few main regions in my classes: private members, properties, constructors, methods, static methods etc. This has the wonderful direct effect of when I open one of my classes and I want to find property blah, I can pop open the properties region and it's there (I know I can use the drop-downs at the top of the code window but that's no fun!). It also has the, arguably, more useful side-effect of keeping all like-things together, so that when new people look at the code, it's much harder for them to put new properties at the bottom of the file instead of with the other properties. My logic here is, let's face it, most of us coders are "OCD" in the sense that we like order and symmetry and things like that, so putting a property outside of the properties region that's already defined makes you feel 'icky' and you want to move it. That's my 37 cents anyway...


                                          Typical n-tiered architecture: DB <-> Junk(0) <-> ... <-> Junk(n-1) <-> Pretty

                                          J 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