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.
  • A Offline
    A Offline
    AspDotNetDev
    wrote on last edited by
    #1

    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
    A B L P S 20 Replies 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
      A Offline
      A Offline
      AspDotNetDev
      wrote on last edited by
      #2

      For anybody reading the above curious how to collapse LI tags...

      Tools > Options > Text Editor > HTML > Formatting > Tag Specific Options... > Client HTML Tags > li > Enable outlining for tag

      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
        B Offline
        B Offline
        BillWoodruff
        wrote on last edited by
        #3

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

          I use regions extensively. Right now I'm looking at a class with no less than 4000 lines. Scrolling up and down, possibly even with all methods and properties unsorted would drive me crazy in a very short time. This class has endless lists of methods (public and private), properties and member variables. On top of this it defines a handsome list of events and also has many properties and methods which must be kept thread safe. And yes, it needs all this functionality because its name is 'Control' and is the base class for all controls in my XNA GUI. And who would I try to hide excessive code from anyway? Myself?

          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
            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            I'm not a big fan of it, but I can pretty much just ignore it. I do use regions in some cases and collapse them, but otherwise I don't collapse anything.

            L 1 Reply Last reply
            0
            • P PIEBALDconsult

              I'm not a big fan of it, but I can pretty much just ignore it. I do use regions in some cases and collapse them, but otherwise I don't collapse anything.

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

              Let me guess: You write mostly 'Ravioli code' like web applications where you can pack most things into small overlookable classes and methods. I feel more at home with complex logic like parsers or rendering and graphics. You can't keep things as neat there.

              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.

              P 1 Reply Last reply
              0
              • L Lost User

                Let me guess: You write mostly 'Ravioli code' like web applications where you can pack most things into small overlookable classes and methods. I feel more at home with complex logic like parsers or rendering and graphics. You can't keep things as neat there.

                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.

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

                Primarily backend / database, but yeah, maybe ravioli kinda describes it. You're welcome to read my articles... :-D

                L 1 Reply Last reply
                0
                • P PIEBALDconsult

                  Primarily backend / database, but yeah, maybe ravioli kinda describes it. You're welcome to read my articles... :-D

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

                  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.

                  Richard Andrew x64R C 2 Replies 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
                    Steve Wellens
                    wrote on last edited by
                    #9

                    Thanks for the new wrinkle on this subject.

                    Steve Wellens

                    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.

                      Richard Andrew x64R Offline
                      Richard Andrew x64R Offline
                      Richard Andrew x64
                      wrote on last edited by
                      #10

                      Ravioli with Rock Lobster sauce? :cool:

                      The difficult we do right away... ...the impossible takes slightly longer.

                      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
                        SimulationofSai
                        wrote on last edited by
                        #11

                        +5 I make liberal use of regions but in such a way as to make navigation within the code easier for me to look at later. The usual things like methods, properties etc but in some cases, my comments are quite large and I enclose them in separate region tags. Some classes and methods I write do pretty complicated stuff which cannot be explained in single line comments.

                        SG Aham Brahmasmi!

                        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
                          C Offline
                          C Offline
                          Chris Losinger
                          wrote on last edited by
                          #12

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

                          image processing toolkits | batch image processing

                          A L 2 Replies 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

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