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. Source code formatting and regions

Source code formatting and regions

Scheduled Pinned Locked Moved The Lounge
toolshelptutorialquestion
23 Posts 13 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D dan sh

    I always use regions for methods, contructors, events, properties, variables and constants. This helps if I have to track something in a large code. I think they are good as if someome else has to maintain your code, it will be easy for him/her to understand what all is written in the code and where to find it. As far as tools are concerned, I have not used any. It will be good if people recommend something.

    जय हिंद

    M Offline
    M Offline
    Martin Hart Turner
    wrote on last edited by
    #6

    Yup, that's more or less why I use them, it make finding code so much easier. Regards, Martin.

    1 Reply Last reply
    0
    • M Martin Hart Turner

      Hi: Do you do source code formatting and/or arranging? What about regions, do you think they are good or evil? Why? I'm afraid I'm a bit of an obsessive compulsive as far as source code is concerned, I have my predefined regions and my code must comply with the Microsoft Style Guidelines, which makes programming quite a task! What tools are available to help me on my personal quest for formatting and arranging? Does anyone have more information (apart from whats available on the web site) on how to use NArrange? Regards, Martin.

      S Offline
      S Offline
      Simon P Stevens
      wrote on last edited by
      #7

      I wrote an AI using neural networks hosted on Amazon EC2 that processes my code and intelligently formats it all correctly. So far it only works with empty files, but I'm hoping to release a beta soon that works with files up to 1 byte long.

      Simon

      M 1 Reply Last reply
      0
      • S Simon P Stevens

        I wrote an AI using neural networks hosted on Amazon EC2 that processes my code and intelligently formats it all correctly. So far it only works with empty files, but I'm hoping to release a beta soon that works with files up to 1 byte long.

        Simon

        M Offline
        M Offline
        Martin Hart Turner
        wrote on last edited by
        #8

        Simon: I'll have to wait for the next version as my code is Unicode and I'll need the 2 byte version ;)

        1 Reply Last reply
        0
        • M Martin Hart Turner

          Hi: Do you do source code formatting and/or arranging? What about regions, do you think they are good or evil? Why? I'm afraid I'm a bit of an obsessive compulsive as far as source code is concerned, I have my predefined regions and my code must comply with the Microsoft Style Guidelines, which makes programming quite a task! What tools are available to help me on my personal quest for formatting and arranging? Does anyone have more information (apart from whats available on the web site) on how to use NArrange? Regards, Martin.

          S Offline
          S Offline
          selcuks
          wrote on last edited by
          #9

          I believe that your classes should be short enough not to confuse you or anyone who reads your code. Large source code can always be divided to smaller modules to complete the same task. (which also increases the readability.) Well that's why I have never needed regions. I also mark public/private members with comments. In my projects, I use StyleCop[^] and I am happy with the results. Hope this helps, Regards.

          Always keep the Murphy Rules in mind!

          1 Reply Last reply
          0
          • M Martin Hart Turner

            Hi: Do you do source code formatting and/or arranging? What about regions, do you think they are good or evil? Why? I'm afraid I'm a bit of an obsessive compulsive as far as source code is concerned, I have my predefined regions and my code must comply with the Microsoft Style Guidelines, which makes programming quite a task! What tools are available to help me on my personal quest for formatting and arranging? Does anyone have more information (apart from whats available on the web site) on how to use NArrange? Regards, Martin.

            H Offline
            H Offline
            Henry Minute
            wrote on last edited by
            #10

            I really, really, no, I mean REALLY dislike over regionalization, especially nested regions, the work of the devil. I generally only have one region, for properties, since for the most part they are simply accessors for private fields which are in plain view. Other than that, I lay my code out in the same order all the time, constants fields event declarations constructor and constructor related methods (Initialization stuff etc.) public methods private methods overrides properties event handlers. Luckily I only have myself to please, but it works for me.

            Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

            R 1 Reply Last reply
            0
            • M Martin Hart Turner

              Hi: Do you do source code formatting and/or arranging? What about regions, do you think they are good or evil? Why? I'm afraid I'm a bit of an obsessive compulsive as far as source code is concerned, I have my predefined regions and my code must comply with the Microsoft Style Guidelines, which makes programming quite a task! What tools are available to help me on my personal quest for formatting and arranging? Does anyone have more information (apart from whats available on the web site) on how to use NArrange? Regards, Martin.

              M Offline
              M Offline
              Mustafa Ismail Mustafa
              wrote on last edited by
              #11

              With almost religious fanaticism and zeal. I feel that code that isn't formatted properly and documented properly is half a step away from being thrown onto the rubbish pile. Every class without fail is divided as follows:

              #region Using Directives
              #endregion

              [scope] class classname
              {
              #region Enumerations
              #endregion

              #region Fields
              #endregion

              #region Properties
              #endregion

              #region Methods
              #endregion

              #region Static Methods
              #endregion

              #region Constructors
              #endregion

              #region EventHandlers
              #endregion

              #region Private Classes
              #endregion
              }

              Destructors are in the same region as the constructors. Every class, method, field, property and event handler (though lately I'm using a lot of automatic properties) are well documented. just my $0.02

              1 Reply Last reply
              0
              • M Martin Hart Turner

                Hi: Do you do source code formatting and/or arranging? What about regions, do you think they are good or evil? Why? I'm afraid I'm a bit of an obsessive compulsive as far as source code is concerned, I have my predefined regions and my code must comply with the Microsoft Style Guidelines, which makes programming quite a task! What tools are available to help me on my personal quest for formatting and arranging? Does anyone have more information (apart from whats available on the web site) on how to use NArrange? Regards, Martin.

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

                Regions are a sin! They are the idle work of the devil! The heathen will use regions to falsely reperesent their code as fitting on one printed page, which we all know is a mortal sin against the all mighty coding principles! Do not succomb to the laziness that this false god desires upon you! Pray instead to the god OOD, to guide you in better architecting your house! Marc

                Will work for food. Interacx

                M 1 Reply Last reply
                0
                • M Marc Clifton

                  Regions are a sin! They are the idle work of the devil! The heathen will use regions to falsely reperesent their code as fitting on one printed page, which we all know is a mortal sin against the all mighty coding principles! Do not succomb to the laziness that this false god desires upon you! Pray instead to the god OOD, to guide you in better architecting your house! Marc

                  Will work for food. Interacx

                  M Offline
                  M Offline
                  Mustafa Ismail Mustafa
                  wrote on last edited by
                  #13

                  Sometimes, you cannot help but have your classes become rather lengthy, Regions are a boon then. Of course, like guns, they can be used for both good and evil.

                  M A 2 Replies Last reply
                  0
                  • M Mustafa Ismail Mustafa

                    Sometimes, you cannot help but have your classes become rather lengthy, Regions are a boon then. Of course, like guns, they can be used for both good and evil.

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

                    Mustafa Ismail Mustafa wrote:

                    Sometimes, you cannot help but have your classes become rather lengthy, Regions are a boon then.

                    Well, there is the "partial" keyword now so you can break up the class. :) Ironically, I never use partial myself. Marc

                    Will work for food. Interacx

                    M 1 Reply Last reply
                    0
                    • M Martin Hart Turner

                      Hi: Do you do source code formatting and/or arranging? What about regions, do you think they are good or evil? Why? I'm afraid I'm a bit of an obsessive compulsive as far as source code is concerned, I have my predefined regions and my code must comply with the Microsoft Style Guidelines, which makes programming quite a task! What tools are available to help me on my personal quest for formatting and arranging? Does anyone have more information (apart from whats available on the web site) on how to use NArrange? Regards, Martin.

                      H Offline
                      H Offline
                      Harvey Saayman
                      wrote on last edited by
                      #15

                      I'm fond of regions The program I'm busy with at the moment(The brains of my system) i have METHODS that are 4000 lines long, so regions are a must IMHO. I also use regions in every class for private variables, Properties, Constructors, Private Methods, Public Methods, etc

                      Harvey Saayman - South Africa Software Developer .Net, C#, SQL you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

                      R 1 Reply Last reply
                      0
                      • H Harvey Saayman

                        I'm fond of regions The program I'm busy with at the moment(The brains of my system) i have METHODS that are 4000 lines long, so regions are a must IMHO. I also use regions in every class for private variables, Properties, Constructors, Private Methods, Public Methods, etc

                        Harvey Saayman - South Africa Software Developer .Net, C#, SQL you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

                        R Offline
                        R Offline
                        Ray Cassick
                        wrote on last edited by
                        #16

                        Harvey Saayman wrote:

                        i have METHODS that are 4000 lines long

                        Really? A method that long? No possible way to bust it up at all?


                        LinkedIn[^] | Blog[^] | Twitter[^]

                        H 1 Reply Last reply
                        0
                        • M Marc Clifton

                          Mustafa Ismail Mustafa wrote:

                          Sometimes, you cannot help but have your classes become rather lengthy, Regions are a boon then.

                          Well, there is the "partial" keyword now so you can break up the class. :) Ironically, I never use partial myself. Marc

                          Will work for food. Interacx

                          M Offline
                          M Offline
                          Mustafa Ismail Mustafa
                          wrote on last edited by
                          #17

                          Marc Clifton wrote:

                          Ironically, I never use partial myself.

                          Ditto. It just doesn't register in my mind to do that.

                          1 Reply Last reply
                          0
                          • R Ray Cassick

                            Harvey Saayman wrote:

                            i have METHODS that are 4000 lines long

                            Really? A method that long? No possible way to bust it up at all?


                            LinkedIn[^] | Blog[^] | Twitter[^]

                            H Offline
                            H Offline
                            Harvey Saayman
                            wrote on last edited by
                            #18

                            That method is the main calculation method for that program... And it IS busted up into smaller parts(Helper methods). It can be further split up, but not at the moment. This biggest reason is that I'm prototyping it using Linq instead of plain old ADO, and I cant pass a Linq result set around. So I'll have to pass the primary keys around, and query again in the helper method itself. That'll be a pain, especially if i need to change a query.

                            Harvey Saayman - South Africa Software Developer .Net, C#, SQL you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

                            R 1 Reply Last reply
                            0
                            • H Harvey Saayman

                              That method is the main calculation method for that program... And it IS busted up into smaller parts(Helper methods). It can be further split up, but not at the moment. This biggest reason is that I'm prototyping it using Linq instead of plain old ADO, and I cant pass a Linq result set around. So I'll have to pass the primary keys around, and query again in the helper method itself. That'll be a pain, especially if i need to change a query.

                              Harvey Saayman - South Africa Software Developer .Net, C#, SQL you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

                              R Offline
                              R Offline
                              Ray Cassick
                              wrote on last edited by
                              #19

                              Ahhh... One of the things that scares me a bit about using LINQ.


                              LinkedIn[^] | Blog[^] | Twitter[^]

                              H 1 Reply Last reply
                              0
                              • H Henry Minute

                                I really, really, no, I mean REALLY dislike over regionalization, especially nested regions, the work of the devil. I generally only have one region, for properties, since for the most part they are simply accessors for private fields which are in plain view. Other than that, I lay my code out in the same order all the time, constants fields event declarations constructor and constructor related methods (Initialization stuff etc.) public methods private methods overrides properties event handlers. Luckily I only have myself to please, but it works for me.

                                Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                                R Offline
                                R Offline
                                Ray Cassick
                                wrote on last edited by
                                #20

                                Henry Minute wrote:

                                I lay my code out in the same order all the time,

                                I do that to... I just wrap my sections into regions :) I just wish that I could force VS to stuff new event handlers into specific region for me instead of me having to do it on my own. I also wish that it would put them at the current cursor location instead of always at the bottom. I could swear that the VB6 editor used to do that.


                                LinkedIn[^] | Blog[^] | Twitter[^]

                                1 Reply Last reply
                                0
                                • R Ray Cassick

                                  Ahhh... One of the things that scares me a bit about using LINQ.


                                  LinkedIn[^] | Blog[^] | Twitter[^]

                                  H Offline
                                  H Offline
                                  Harvey Saayman
                                  wrote on last edited by
                                  #21

                                  Don't get me wrong :) I'm a big fan of the Linq. It works really well in my front end. But the performance penalty became very clear after i started to write my calculation program, which basically processes all the information in the database and writes the output to 3 or 4 tables. Currently it runs for 6 to 7 minutes with less input than some of our clients will supply it with in 5 minutes of usage :suss:

                                  Harvey Saayman - South Africa Software Developer .Net, C#, SQL you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

                                  1 Reply Last reply
                                  0
                                  • M Martin Hart Turner

                                    Hi: Do you do source code formatting and/or arranging? What about regions, do you think they are good or evil? Why? I'm afraid I'm a bit of an obsessive compulsive as far as source code is concerned, I have my predefined regions and my code must comply with the Microsoft Style Guidelines, which makes programming quite a task! What tools are available to help me on my personal quest for formatting and arranging? Does anyone have more information (apart from whats available on the web site) on how to use NArrange? Regards, Martin.

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

                                    Yes. Actually I only use regions in code that I intend to publish here, in an attempt to assist the reader. They have no affect when I'm writing code in Edit.

                                    1 Reply Last reply
                                    0
                                    • M Mustafa Ismail Mustafa

                                      Sometimes, you cannot help but have your classes become rather lengthy, Regions are a boon then. Of course, like guns, they can be used for both good and evil.

                                      A Offline
                                      A Offline
                                      Anna Jayne Metcalfe
                                      wrote on last edited by
                                      #23

                                      Mustafa Ismail Mustafa wrote:

                                      Sometimes, you cannot help but have your classes become rather lengthy

                                      Why? Seriously, a long class is a strong indication of a sub-optimal design. if you design with the Single Responsibility Principle[^] in mind you will find that long classes tend not to occur in the first place!

                                      Anna :rose: Having a bad bug day? Tech Blog | Anna's Place | Tears and Laughter "If mushy peas are the food of the devil, the stotty cake is the frisbee of God"

                                      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