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. Code Folding (Regions)

Code Folding (Regions)

Scheduled Pinned Locked Moved The Lounge
csharphtmlcssvisual-studiocom
34 Posts 22 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.
  • C Chris Losinger

    if you need to fold, maybe you have too much stuff in that one file.

    image processing toolkits | batch image processing

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

    Nobody said anything about needing to fold. I just think it makes it easier to code. Like comments, which are not strictly needed, but make coding easier.

    Somebody in an online forum wrote:

    INTJs never really joke. They make a point. The joke is just a gift wrapper.

    1 Reply Last reply
    0
    • B BillWoodruff

      I like code-folding as an option ! I think judicious use of it often helps me switch from narrow-focus on some particular functionality back to 'big-picture' view. I have wished for the ability to 'fold' ... just one level of folding would do ... in CP articles :) ... imho this would enable having a top-level highly readable article with lots of minute-details, digressions, footnotes, etc., hidden, but available. best, Bill

      "Use the word 'cybernetics,' Norbert, because nobody knows what it means. This will always put you at an advantage in arguments." Claude Shannon (Information Theory scientist): letter to Norbert Weiner of M.I.T., circa 1940

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

      BillWoodruff wrote:

      I think judicious use of it often helps me switch from narrow-focus on some particular functionality back to 'big-picture' view

      I agree with this. The same principle applies to comments, and those who think code is self-documenting don't seem to get that. Sure, you might be able to get what the code does relatively easily by reading it, by why not save some time and read a comment that explains it more succintly instead? And having them at different levels (group of code, method, region, class, project, application) gives you more choice of exactly at what level you want to understand the code.

      BillWoodruff wrote:

      I have wished for the ability to 'fold' ... just one level of folding would do ... in CP articles

      That's actually something on my TODO list... I want to find out if there is some way to do folding (of sorts) in the company wiki (useful for instruction documents that go into great detail but only need to be read at a higher detail for those who are more experienced).

      Somebody in an online forum wrote:

      INTJs never really joke. They make a point. The joke is just a gift wrapper.

      1 Reply Last reply
      0
      • A AspDotNetDev

        I was just searching for a way to collapse LI tags in the Visual Studio editor without having to manually right click it and select "collapse tag" when I got distracted and read Coding Horror: The Problem with Code Folding. I am a big fan of code folding, and here are some points Jeff makes that I disagree with:

        1. "I can't see anything!" Actually, you can. You can see the first line of whatever is being folded. In the case of regions, you can see the name of the region. When I am doing web development, I tend to wrap code into regions like "Event Handlers" and "Private Methods". If I want to get a feel for how the program flows, I go straight to "Event Handlers" and look for something that looks like the page load event handler (or init, or what have you). Or if there are constructors, I'll look there first. If I just want to see what properties are available in a user control, I'll go to "Properties" (and since the properties are folded, I can ignore their implementation). I find hiding stuff I don't need to see speeds this process up.
        2. "Folding directives are glorified comments. Why, exactly, are we writing code to accomodate the editor?" Comments are good. Regions are like comments with a bonus feature (folding a region of code that doesn't otherwise get folded). That's not a bad thing. And we're not accomodating the editor... we're accomodating ourselves and other developers who will come in later to see nicely organized code.
        3. "Folding is used to sweep code under the rung. Folding is used to mask excessive length." No doubt, when it's used wrong. Just don't use it wrong. Simples. Still, there is some value in hiding information that you don't need (it distracts you less and frees your mind to think of what you are trying to focus on).
        4. "Folding can hide deficiencies in your editor." From another perspective, it replaces a feature seen in other editors. Sometimes I may want to put all my methods into a "Methods" region. Or maybe I'll put them into "Public Methods" and "Private Methods" regions. Or maybe I'll put event handler methods into "Event Handlers". And so on. Relying on an editor to group these sections automatically may be less flexible and so less useful than if a developer were to choose the regions himself or herself. Perhaps a conversion class is organized into regions according to what data type a method operates on and maybe a user control class
        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #15

        AspDotNetDev wrote:

        Folding is used to sweep code under the rung

        I hope he means rug, I'd hate to have to carry a ladder to work. I'm a boring class per file kind of guy but I work on a pretty big c++ code base so the granularity of header files and their use can have a big impact on build times. I thought the regions were pretty cool in c#, what I disliked was the partial keyword and classes spread across multiple files.

        A P 2 Replies Last reply
        0
        • L Lost User

          AspDotNetDev wrote:

          Folding is used to sweep code under the rung

          I hope he means rug, I'd hate to have to carry a ladder to work. I'm a boring class per file kind of guy but I work on a pretty big c++ code base so the granularity of header files and their use can have a big impact on build times. I thought the regions were pretty cool in c#, what I disliked was the partial keyword and classes spread across multiple files.

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

          :laugh: If the darn paste functionality wasn't so munged up, I wouldn't have made that mistake. And uses for the partial keyword by a developer seem rare, excluding their main use (splitting out code for the designer file).

          Somebody in an online forum wrote:

          INTJs never really joke. They make a point. The joke is just a gift wrapper.

          1 Reply Last reply
          0
          • L Lost User

            I liked that term when I first heard it as opposite to Spaghetti code. :) And there also was Lasagna as description for strictly layered code. Hmm, for application logic and data access you best use both Ravioli code which at the same time is Lasagna code. This is getting confusing and making me hungry :)

            And from the clouds a mighty voice spoke:
            "Smile and be happy, for it could come worse!"

            And I smiled and was happy
            And it came worse.

            C Offline
            C Offline
            Chris C B
            wrote on last edited by
            #17

            I usually write fusilli[^] code - it's really screwed up! :cool: :laugh:

            1 Reply Last reply
            0
            • C Chris Losinger

              if you need to fold, maybe you have too much stuff in that one file.

              image processing toolkits | batch image processing

              L Offline
              L Offline
              l a u r e n
              wrote on last edited by
              #18

              +1 for us dinosaurs :)

              "mostly watching the human race is like watching dogs watch tv ... they see the pictures move but the meaning escapes them"

              1 Reply Last reply
              0
              • A AspDotNetDev

                I was just searching for a way to collapse LI tags in the Visual Studio editor without having to manually right click it and select "collapse tag" when I got distracted and read Coding Horror: The Problem with Code Folding. I am a big fan of code folding, and here are some points Jeff makes that I disagree with:

                1. "I can't see anything!" Actually, you can. You can see the first line of whatever is being folded. In the case of regions, you can see the name of the region. When I am doing web development, I tend to wrap code into regions like "Event Handlers" and "Private Methods". If I want to get a feel for how the program flows, I go straight to "Event Handlers" and look for something that looks like the page load event handler (or init, or what have you). Or if there are constructors, I'll look there first. If I just want to see what properties are available in a user control, I'll go to "Properties" (and since the properties are folded, I can ignore their implementation). I find hiding stuff I don't need to see speeds this process up.
                2. "Folding directives are glorified comments. Why, exactly, are we writing code to accomodate the editor?" Comments are good. Regions are like comments with a bonus feature (folding a region of code that doesn't otherwise get folded). That's not a bad thing. And we're not accomodating the editor... we're accomodating ourselves and other developers who will come in later to see nicely organized code.
                3. "Folding is used to sweep code under the rung. Folding is used to mask excessive length." No doubt, when it's used wrong. Just don't use it wrong. Simples. Still, there is some value in hiding information that you don't need (it distracts you less and frees your mind to think of what you are trying to focus on).
                4. "Folding can hide deficiencies in your editor." From another perspective, it replaces a feature seen in other editors. Sometimes I may want to put all my methods into a "Methods" region. Or maybe I'll put them into "Public Methods" and "Private Methods" regions. Or maybe I'll put event handler methods into "Event Handlers". And so on. Relying on an editor to group these sections automatically may be less flexible and so less useful than if a developer were to choose the regions himself or herself. Perhaps a conversion class is organized into regions according to what data type a method operates on and maybe a user control class
                G Offline
                G Offline
                Gary R Wheeler
                wrote on last edited by
                #19

                Like any other tool, regions can be misused. The example Jeff cites is just such a misuse. I would guess it resulted from a source code template imposed by the local programming style. You've probably seen this before: lots of block comments (and regions in this case) with "fill-in-the-blank" spots, most of which are left blank. When used properly regions help in the middle ground, when a class is large enough that some meta-organization beyond the methods themselves is useful. I tend to organize regions conceptually: initialization/termination, fundamental properties, public operations, internals. If you have regions wrapping groups of regions (I've seen this on occasion), then that's an indication some serious refactoring is in order.

                Software Zen: delete this;

                1 Reply Last reply
                0
                • A AspDotNetDev

                  I was just searching for a way to collapse LI tags in the Visual Studio editor without having to manually right click it and select "collapse tag" when I got distracted and read Coding Horror: The Problem with Code Folding. I am a big fan of code folding, and here are some points Jeff makes that I disagree with:

                  1. "I can't see anything!" Actually, you can. You can see the first line of whatever is being folded. In the case of regions, you can see the name of the region. When I am doing web development, I tend to wrap code into regions like "Event Handlers" and "Private Methods". If I want to get a feel for how the program flows, I go straight to "Event Handlers" and look for something that looks like the page load event handler (or init, or what have you). Or if there are constructors, I'll look there first. If I just want to see what properties are available in a user control, I'll go to "Properties" (and since the properties are folded, I can ignore their implementation). I find hiding stuff I don't need to see speeds this process up.
                  2. "Folding directives are glorified comments. Why, exactly, are we writing code to accomodate the editor?" Comments are good. Regions are like comments with a bonus feature (folding a region of code that doesn't otherwise get folded). That's not a bad thing. And we're not accomodating the editor... we're accomodating ourselves and other developers who will come in later to see nicely organized code.
                  3. "Folding is used to sweep code under the rung. Folding is used to mask excessive length." No doubt, when it's used wrong. Just don't use it wrong. Simples. Still, there is some value in hiding information that you don't need (it distracts you less and frees your mind to think of what you are trying to focus on).
                  4. "Folding can hide deficiencies in your editor." From another perspective, it replaces a feature seen in other editors. Sometimes I may want to put all my methods into a "Methods" region. Or maybe I'll put them into "Public Methods" and "Private Methods" regions. Or maybe I'll put event handler methods into "Event Handlers". And so on. Relying on an editor to group these sections automatically may be less flexible and so less useful than if a developer were to choose the regions himself or herself. Perhaps a conversion class is organized into regions according to what data type a method operates on and maybe a user control class
                  B Offline
                  B Offline
                  Brady Kelly
                  wrote on last edited by
                  #20

                  I like regions, but seldom use them. I normally use them to help me arrange existing code to better understand it.

                  1 Reply Last reply
                  0
                  • L Lost User

                    AspDotNetDev wrote:

                    Folding is used to sweep code under the rung

                    I hope he means rug, I'd hate to have to carry a ladder to work. I'm a boring class per file kind of guy but I work on a pretty big c++ code base so the granularity of header files and their use can have a big impact on build times. I thought the regions were pretty cool in c#, what I disliked was the partial keyword and classes spread across multiple files.

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

                    _Josh_ wrote:

                    the partial keyword

                    I'm rather partial to it myself. I can write a Data Access Layer with separate files for each table. They give us back what C++ already had. On the other hand, I don't agree with needing a keyword, all classes should be partial automatically.

                    1 Reply Last reply
                    0
                    • A AspDotNetDev

                      I was just searching for a way to collapse LI tags in the Visual Studio editor without having to manually right click it and select "collapse tag" when I got distracted and read Coding Horror: The Problem with Code Folding. I am a big fan of code folding, and here are some points Jeff makes that I disagree with:

                      1. "I can't see anything!" Actually, you can. You can see the first line of whatever is being folded. In the case of regions, you can see the name of the region. When I am doing web development, I tend to wrap code into regions like "Event Handlers" and "Private Methods". If I want to get a feel for how the program flows, I go straight to "Event Handlers" and look for something that looks like the page load event handler (or init, or what have you). Or if there are constructors, I'll look there first. If I just want to see what properties are available in a user control, I'll go to "Properties" (and since the properties are folded, I can ignore their implementation). I find hiding stuff I don't need to see speeds this process up.
                      2. "Folding directives are glorified comments. Why, exactly, are we writing code to accomodate the editor?" Comments are good. Regions are like comments with a bonus feature (folding a region of code that doesn't otherwise get folded). That's not a bad thing. And we're not accomodating the editor... we're accomodating ourselves and other developers who will come in later to see nicely organized code.
                      3. "Folding is used to sweep code under the rung. Folding is used to mask excessive length." No doubt, when it's used wrong. Just don't use it wrong. Simples. Still, there is some value in hiding information that you don't need (it distracts you less and frees your mind to think of what you are trying to focus on).
                      4. "Folding can hide deficiencies in your editor." From another perspective, it replaces a feature seen in other editors. Sometimes I may want to put all my methods into a "Methods" region. Or maybe I'll put them into "Public Methods" and "Private Methods" regions. Or maybe I'll put event handler methods into "Event Handlers". And so on. Relying on an editor to group these sections automatically may be less flexible and so less useful than if a developer were to choose the regions himself or herself. Perhaps a conversion class is organized into regions according to what data type a method operates on and maybe a user control class
                      W Offline
                      W Offline
                      was8309
                      wrote on last edited by
                      #22

                      +5 here too. when playing w/ C# in visual studio express and saw folding (about 5 years ago) i had to get a text editor w/ folding (settled on JEdit). The IBM Mainframe ISPF editor has an 'exclude line' feature for hiding what is currently noise, but lines must be hidden manually. So with Jedit set as 'fold per indent' all my todo lists look like Python scripts.

                      1 Reply Last reply
                      0
                      • A AspDotNetDev

                        I was just searching for a way to collapse LI tags in the Visual Studio editor without having to manually right click it and select "collapse tag" when I got distracted and read Coding Horror: The Problem with Code Folding. I am a big fan of code folding, and here are some points Jeff makes that I disagree with:

                        1. "I can't see anything!" Actually, you can. You can see the first line of whatever is being folded. In the case of regions, you can see the name of the region. When I am doing web development, I tend to wrap code into regions like "Event Handlers" and "Private Methods". If I want to get a feel for how the program flows, I go straight to "Event Handlers" and look for something that looks like the page load event handler (or init, or what have you). Or if there are constructors, I'll look there first. If I just want to see what properties are available in a user control, I'll go to "Properties" (and since the properties are folded, I can ignore their implementation). I find hiding stuff I don't need to see speeds this process up.
                        2. "Folding directives are glorified comments. Why, exactly, are we writing code to accomodate the editor?" Comments are good. Regions are like comments with a bonus feature (folding a region of code that doesn't otherwise get folded). That's not a bad thing. And we're not accomodating the editor... we're accomodating ourselves and other developers who will come in later to see nicely organized code.
                        3. "Folding is used to sweep code under the rung. Folding is used to mask excessive length." No doubt, when it's used wrong. Just don't use it wrong. Simples. Still, there is some value in hiding information that you don't need (it distracts you less and frees your mind to think of what you are trying to focus on).
                        4. "Folding can hide deficiencies in your editor." From another perspective, it replaces a feature seen in other editors. Sometimes I may want to put all my methods into a "Methods" region. Or maybe I'll put them into "Public Methods" and "Private Methods" regions. Or maybe I'll put event handler methods into "Event Handlers". And so on. Relying on an editor to group these sections automatically may be less flexible and so less useful than if a developer were to choose the regions himself or herself. Perhaps a conversion class is organized into regions according to what data type a method operates on and maybe a user control class
                        B Offline
                        B Offline
                        BobJanova
                        wrote on last edited by
                        #23

                        Having had to work on a codebase written by others using regions extensively, I can say with some certainty that they make it a pain in the arse to navigate through the code and find out what is happening. And if your file is long enough that you think you need them, there's probably some refactoring to be done – it's very easy to use regions to 'tidy up' your code and find that you just keep adding things because you never get the 'oh my I'm doing a lot of scrolling, time to refactor' reaction. Being able to roll up methods and classes is nice (though I never do that either, I use the method selector or page up/down to navigate files), but I find that regions just hide things,

                        L 1 Reply Last reply
                        0
                        • B BobJanova

                          Having had to work on a codebase written by others using regions extensively, I can say with some certainty that they make it a pain in the arse to navigate through the code and find out what is happening. And if your file is long enough that you think you need them, there's probably some refactoring to be done – it's very easy to use regions to 'tidy up' your code and find that you just keep adding things because you never get the 'oh my I'm doing a lot of scrolling, time to refactor' reaction. Being able to roll up methods and classes is nice (though I never do that either, I use the method selector or page up/down to navigate files), but I find that regions just hide things,

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

                          BobJanova wrote:

                          there's probably some refactoring to be done

                          Really? Just keep in mind that there are classes which do a little more than pass around data from and to the database. Not everything is a web application. It's not really fair to suggest that somebody is probably sloppy just because he needs larger classes and needs to organize them a bit more.

                          BobJanova wrote:

                          but I find that regions just hide things,

                          That's the idea. If you have dozens of members, properties, methods, events or whatever it's nice to have a way to make those things which you don't care about at the moment disappear. For example, in my control base class I mentioned before, I may want to see everything what has to do with rendering, and not the stuff for processing input.

                          And from the clouds a mighty voice spoke:
                          "Smile and be happy, for it could come worse!"

                          And I smiled and was happy
                          And it came worse.

                          1 Reply Last reply
                          0
                          • A AspDotNetDev

                            I was just searching for a way to collapse LI tags in the Visual Studio editor without having to manually right click it and select "collapse tag" when I got distracted and read Coding Horror: The Problem with Code Folding. I am a big fan of code folding, and here are some points Jeff makes that I disagree with:

                            1. "I can't see anything!" Actually, you can. You can see the first line of whatever is being folded. In the case of regions, you can see the name of the region. When I am doing web development, I tend to wrap code into regions like "Event Handlers" and "Private Methods". If I want to get a feel for how the program flows, I go straight to "Event Handlers" and look for something that looks like the page load event handler (or init, or what have you). Or if there are constructors, I'll look there first. If I just want to see what properties are available in a user control, I'll go to "Properties" (and since the properties are folded, I can ignore their implementation). I find hiding stuff I don't need to see speeds this process up.
                            2. "Folding directives are glorified comments. Why, exactly, are we writing code to accomodate the editor?" Comments are good. Regions are like comments with a bonus feature (folding a region of code that doesn't otherwise get folded). That's not a bad thing. And we're not accomodating the editor... we're accomodating ourselves and other developers who will come in later to see nicely organized code.
                            3. "Folding is used to sweep code under the rung. Folding is used to mask excessive length." No doubt, when it's used wrong. Just don't use it wrong. Simples. Still, there is some value in hiding information that you don't need (it distracts you less and frees your mind to think of what you are trying to focus on).
                            4. "Folding can hide deficiencies in your editor." From another perspective, it replaces a feature seen in other editors. Sometimes I may want to put all my methods into a "Methods" region. Or maybe I'll put them into "Public Methods" and "Private Methods" regions. Or maybe I'll put event handler methods into "Event Handlers". And so on. Relying on an editor to group these sections automatically may be less flexible and so less useful than if a developer were to choose the regions himself or herself. Perhaps a conversion class is organized into regions according to what data type a method operates on and maybe a user control class
                            I Offline
                            I Offline
                            ii_noname_ii
                            wrote on last edited by
                            #25

                            Regions are a vital part of readable code... I usually split them up into control events: #Region [control name] Events .. Then the allmighty allimportant underused keyboard shortcut: Ctrl+M Ctrl+O.

                            I 1 Reply Last reply
                            0
                            • I ii_noname_ii

                              Regions are a vital part of readable code... I usually split them up into control events: #Region [control name] Events .. Then the allmighty allimportant underused keyboard shortcut: Ctrl+M Ctrl+O.

                              I Offline
                              I Offline
                              ii_noname_ii
                              wrote on last edited by
                              #26

                              ..And BTW... I saw some screenshots of the next Visual Studio, and it seems that you can see all your functions, routines, regions(?), on the solution explorer. Don't know if any current versions have this. I'm still on VS2008 sp1... Can't wait to get an upgrade.

                              1 Reply Last reply
                              0
                              • A AspDotNetDev

                                I was just searching for a way to collapse LI tags in the Visual Studio editor without having to manually right click it and select "collapse tag" when I got distracted and read Coding Horror: The Problem with Code Folding. I am a big fan of code folding, and here are some points Jeff makes that I disagree with:

                                1. "I can't see anything!" Actually, you can. You can see the first line of whatever is being folded. In the case of regions, you can see the name of the region. When I am doing web development, I tend to wrap code into regions like "Event Handlers" and "Private Methods". If I want to get a feel for how the program flows, I go straight to "Event Handlers" and look for something that looks like the page load event handler (or init, or what have you). Or if there are constructors, I'll look there first. If I just want to see what properties are available in a user control, I'll go to "Properties" (and since the properties are folded, I can ignore their implementation). I find hiding stuff I don't need to see speeds this process up.
                                2. "Folding directives are glorified comments. Why, exactly, are we writing code to accomodate the editor?" Comments are good. Regions are like comments with a bonus feature (folding a region of code that doesn't otherwise get folded). That's not a bad thing. And we're not accomodating the editor... we're accomodating ourselves and other developers who will come in later to see nicely organized code.
                                3. "Folding is used to sweep code under the rung. Folding is used to mask excessive length." No doubt, when it's used wrong. Just don't use it wrong. Simples. Still, there is some value in hiding information that you don't need (it distracts you less and frees your mind to think of what you are trying to focus on).
                                4. "Folding can hide deficiencies in your editor." From another perspective, it replaces a feature seen in other editors. Sometimes I may want to put all my methods into a "Methods" region. Or maybe I'll put them into "Public Methods" and "Private Methods" regions. Or maybe I'll put event handler methods into "Event Handlers". And so on. Relying on an editor to group these sections automatically may be less flexible and so less useful than if a developer were to choose the regions himself or herself. Perhaps a conversion class is organized into regions according to what data type a method operates on and maybe a user control class
                                B Offline
                                B Offline
                                BruceClegg
                                wrote on last edited by
                                #27

                                I love code folding. We have a complicated Web application with hundreds of pages that we are moving to a common .NET architecture, with base classes for different screen types (Criteria, List or Detail) . My developers all put the code in the same sections, so it makes it very helpful for debugging. The larger the development team the more benefit realized from standardization.

                                1 Reply Last reply
                                0
                                • A AspDotNetDev

                                  I was just searching for a way to collapse LI tags in the Visual Studio editor without having to manually right click it and select "collapse tag" when I got distracted and read Coding Horror: The Problem with Code Folding. I am a big fan of code folding, and here are some points Jeff makes that I disagree with:

                                  1. "I can't see anything!" Actually, you can. You can see the first line of whatever is being folded. In the case of regions, you can see the name of the region. When I am doing web development, I tend to wrap code into regions like "Event Handlers" and "Private Methods". If I want to get a feel for how the program flows, I go straight to "Event Handlers" and look for something that looks like the page load event handler (or init, or what have you). Or if there are constructors, I'll look there first. If I just want to see what properties are available in a user control, I'll go to "Properties" (and since the properties are folded, I can ignore their implementation). I find hiding stuff I don't need to see speeds this process up.
                                  2. "Folding directives are glorified comments. Why, exactly, are we writing code to accomodate the editor?" Comments are good. Regions are like comments with a bonus feature (folding a region of code that doesn't otherwise get folded). That's not a bad thing. And we're not accomodating the editor... we're accomodating ourselves and other developers who will come in later to see nicely organized code.
                                  3. "Folding is used to sweep code under the rung. Folding is used to mask excessive length." No doubt, when it's used wrong. Just don't use it wrong. Simples. Still, there is some value in hiding information that you don't need (it distracts you less and frees your mind to think of what you are trying to focus on).
                                  4. "Folding can hide deficiencies in your editor." From another perspective, it replaces a feature seen in other editors. Sometimes I may want to put all my methods into a "Methods" region. Or maybe I'll put them into "Public Methods" and "Private Methods" regions. Or maybe I'll put event handler methods into "Event Handlers". And so on. Relying on an editor to group these sections automatically may be less flexible and so less useful than if a developer were to choose the regions himself or herself. Perhaps a conversion class is organized into regions according to what data type a method operates on and maybe a user control class
                                  B Offline
                                  B Offline
                                  bougiefever
                                  wrote on last edited by
                                  #28

                                  Regions suck, pure and simple. Except for a few rare exceptions, if I see a lot of regions, it's usually because the class contains too much and needs to be refactored. If your code is well organized, it's easy to find exactly what you're looking for in 2-3 seconds or less. Put all your private field declarations, your internals, your public methods, public properties and constructors in the same order, and you will be able to find everything really quickly. This is my preferred order: Constructors Public properties Public methods Protected properties & methods Internal properties & methods Private methods Private fields Having ReSharper helps a lot too, if you're a .NET developer. Ctrl-Alt-F shows you all your declarations in a nice window with the ability to drag things around. Why create housekeeping tasks with keeping regions neat and tidy? They don't add anything you can't get by just keeping your classes to a reasonable size and being a little bit organized.

                                  F 1 Reply Last reply
                                  0
                                  • A AspDotNetDev

                                    I was just searching for a way to collapse LI tags in the Visual Studio editor without having to manually right click it and select "collapse tag" when I got distracted and read Coding Horror: The Problem with Code Folding. I am a big fan of code folding, and here are some points Jeff makes that I disagree with:

                                    1. "I can't see anything!" Actually, you can. You can see the first line of whatever is being folded. In the case of regions, you can see the name of the region. When I am doing web development, I tend to wrap code into regions like "Event Handlers" and "Private Methods". If I want to get a feel for how the program flows, I go straight to "Event Handlers" and look for something that looks like the page load event handler (or init, or what have you). Or if there are constructors, I'll look there first. If I just want to see what properties are available in a user control, I'll go to "Properties" (and since the properties are folded, I can ignore their implementation). I find hiding stuff I don't need to see speeds this process up.
                                    2. "Folding directives are glorified comments. Why, exactly, are we writing code to accomodate the editor?" Comments are good. Regions are like comments with a bonus feature (folding a region of code that doesn't otherwise get folded). That's not a bad thing. And we're not accomodating the editor... we're accomodating ourselves and other developers who will come in later to see nicely organized code.
                                    3. "Folding is used to sweep code under the rung. Folding is used to mask excessive length." No doubt, when it's used wrong. Just don't use it wrong. Simples. Still, there is some value in hiding information that you don't need (it distracts you less and frees your mind to think of what you are trying to focus on).
                                    4. "Folding can hide deficiencies in your editor." From another perspective, it replaces a feature seen in other editors. Sometimes I may want to put all my methods into a "Methods" region. Or maybe I'll put them into "Public Methods" and "Private Methods" regions. Or maybe I'll put event handler methods into "Event Handlers". And so on. Relying on an editor to group these sections automatically may be less flexible and so less useful than if a developer were to choose the regions himself or herself. Perhaps a conversion class is organized into regions according to what data type a method operates on and maybe a user control class
                                    S Offline
                                    S Offline
                                    snorkie
                                    wrote on last edited by
                                    #29

                                    My biggest complaint of code folding, whether from regions or class level, is that I can't fold from the bottom. In order to fold, you have to go to the top of a region and click the button. When will Visual Studio allow me to fold from the end of a region or class? This would save very tedious scrolling!!! Hogan

                                    1 Reply Last reply
                                    0
                                    • B bougiefever

                                      Regions suck, pure and simple. Except for a few rare exceptions, if I see a lot of regions, it's usually because the class contains too much and needs to be refactored. If your code is well organized, it's easy to find exactly what you're looking for in 2-3 seconds or less. Put all your private field declarations, your internals, your public methods, public properties and constructors in the same order, and you will be able to find everything really quickly. This is my preferred order: Constructors Public properties Public methods Protected properties & methods Internal properties & methods Private methods Private fields Having ReSharper helps a lot too, if you're a .NET developer. Ctrl-Alt-F shows you all your declarations in a nice window with the ability to drag things around. Why create housekeeping tasks with keeping regions neat and tidy? They don't add anything you can't get by just keeping your classes to a reasonable size and being a little bit organized.

                                      F Offline
                                      F Offline
                                      fre0n
                                      wrote on last edited by
                                      #30

                                      +5 for: -Put class members in the same order in every file (although my order is different). -Ctrl-Alt-F. I was unaware of the File Structure window in R# - this pretty much rocks my day.

                                      1 Reply Last reply
                                      0
                                      • A AspDotNetDev

                                        I was just searching for a way to collapse LI tags in the Visual Studio editor without having to manually right click it and select "collapse tag" when I got distracted and read Coding Horror: The Problem with Code Folding. I am a big fan of code folding, and here are some points Jeff makes that I disagree with:

                                        1. "I can't see anything!" Actually, you can. You can see the first line of whatever is being folded. In the case of regions, you can see the name of the region. When I am doing web development, I tend to wrap code into regions like "Event Handlers" and "Private Methods". If I want to get a feel for how the program flows, I go straight to "Event Handlers" and look for something that looks like the page load event handler (or init, or what have you). Or if there are constructors, I'll look there first. If I just want to see what properties are available in a user control, I'll go to "Properties" (and since the properties are folded, I can ignore their implementation). I find hiding stuff I don't need to see speeds this process up.
                                        2. "Folding directives are glorified comments. Why, exactly, are we writing code to accomodate the editor?" Comments are good. Regions are like comments with a bonus feature (folding a region of code that doesn't otherwise get folded). That's not a bad thing. And we're not accomodating the editor... we're accomodating ourselves and other developers who will come in later to see nicely organized code.
                                        3. "Folding is used to sweep code under the rung. Folding is used to mask excessive length." No doubt, when it's used wrong. Just don't use it wrong. Simples. Still, there is some value in hiding information that you don't need (it distracts you less and frees your mind to think of what you are trying to focus on).
                                        4. "Folding can hide deficiencies in your editor." From another perspective, it replaces a feature seen in other editors. Sometimes I may want to put all my methods into a "Methods" region. Or maybe I'll put them into "Public Methods" and "Private Methods" regions. Or maybe I'll put event handler methods into "Event Handlers". And so on. Relying on an editor to group these sections automatically may be less flexible and so less useful than if a developer were to choose the regions himself or herself. Perhaps a conversion class is organized into regions according to what data type a method operates on and maybe a user control class
                                        T Offline
                                        T Offline
                                        TheGreatAndPowerfulOz
                                        wrote on last edited by
                                        #31

                                        I'm ok with Regions when they're used to group functions, methods or properties. Regions within a method or function should be disallowed. Far too many programmers use regions to denote what should be a separate function.

                                        If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
                                        You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun

                                        1 Reply Last reply
                                        0
                                        • A AspDotNetDev

                                          I was just searching for a way to collapse LI tags in the Visual Studio editor without having to manually right click it and select "collapse tag" when I got distracted and read Coding Horror: The Problem with Code Folding. I am a big fan of code folding, and here are some points Jeff makes that I disagree with:

                                          1. "I can't see anything!" Actually, you can. You can see the first line of whatever is being folded. In the case of regions, you can see the name of the region. When I am doing web development, I tend to wrap code into regions like "Event Handlers" and "Private Methods". If I want to get a feel for how the program flows, I go straight to "Event Handlers" and look for something that looks like the page load event handler (or init, or what have you). Or if there are constructors, I'll look there first. If I just want to see what properties are available in a user control, I'll go to "Properties" (and since the properties are folded, I can ignore their implementation). I find hiding stuff I don't need to see speeds this process up.
                                          2. "Folding directives are glorified comments. Why, exactly, are we writing code to accomodate the editor?" Comments are good. Regions are like comments with a bonus feature (folding a region of code that doesn't otherwise get folded). That's not a bad thing. And we're not accomodating the editor... we're accomodating ourselves and other developers who will come in later to see nicely organized code.
                                          3. "Folding is used to sweep code under the rung. Folding is used to mask excessive length." No doubt, when it's used wrong. Just don't use it wrong. Simples. Still, there is some value in hiding information that you don't need (it distracts you less and frees your mind to think of what you are trying to focus on).
                                          4. "Folding can hide deficiencies in your editor." From another perspective, it replaces a feature seen in other editors. Sometimes I may want to put all my methods into a "Methods" region. Or maybe I'll put them into "Public Methods" and "Private Methods" regions. Or maybe I'll put event handler methods into "Event Handlers". And so on. Relying on an editor to group these sections automatically may be less flexible and so less useful than if a developer were to choose the regions himself or herself. Perhaps a conversion class is organized into regions according to what data type a method operates on and maybe a user control class
                                          L Offline
                                          L Offline
                                          Lost User
                                          wrote on last edited by
                                          #32

                                          AspDotNetDev wrote:

                                          What's your take on code folding, especially with respect to regions?

                                          Don't like regions, everybody uses them in a different way and the different groupings that some teams want are merely timewasters. I first came across the concept in Amos BASIC, and I loved it; it was a huge improvement, but it didn't work with regions. Amos collapsed them at the method-level, and if you collapsed them all, you'd be looking at the signatures - comparable to Delphi's interface part of the unit. It worked very well, and I haven't come across a decent code-folding feature since then.

                                          Bastard Programmer from Hell :suss:

                                          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