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. Does not Developers get confused if there are too many global variables?

Does not Developers get confused if there are too many global variables?

Scheduled Pinned Locked Moved The Lounge
architecturequestion
67 Posts 29 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 Maunder

    Mohammed Hameed wrote:

    Is it like they get accustomed to it and hence use it?

    Or they simply don't understand how to write object oriented and/or well architected code.

    cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

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

    Well, hamsters' brains aren't that big ... it's cruel enough making them write JavaScript without expecting good JavaScript.

    R C 2 Replies Last reply
    0
    • M Mohammed Hameed

      It has been noticed that some developers heavily use Global variables, may be without any discomfort. Is it like they get accustomed to it and hence use it? Dont they get confused by over usage?

      Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!

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

      It would depend upon how the variables are named. Names like: jjxl, jixl, picxl, y, x, xy, yx, xxy would be confusing even locally scoped. However, names like: Global_Late_Fee, Global_Post_Date, & WTF_Adjustment aren't confusing.

      L M 2 Replies Last reply
      0
      • L Lost User

        It would depend upon how the variables are named. Names like: jjxl, jixl, picxl, y, x, xy, yx, xxy would be confusing even locally scoped. However, names like: Global_Late_Fee, Global_Post_Date, & WTF_Adjustment aren't confusing.

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

        MehGerbil wrote:

        However, names like: Global_Late_Fee, Global_Post_Date, & WTF_Adjustment aren't confusing.

        ..not confusing mayhaps, just a bad idea :)

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        1 Reply Last reply
        0
        • M Mohammed Hameed

          It has been noticed that some developers heavily use Global variables, may be without any discomfort. Is it like they get accustomed to it and hence use it? Dont they get confused by over usage?

          Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!

          J Offline
          J Offline
          Joe Woodbury
          wrote on last edited by
          #8

          It's less confusing that where the developer uses classes at an absurdly granular level and/or buys into the "a method should do only one thing" nonsense. Then there's the one person who uses "var" for every definition in their C# code. The solution is to write aesthetically pleasing code will with meaningful names. In the C++ world, using static properly is a big help. (One thing that cracks me up are devs who criticize global variables and then create a singleton class full of variables. Or, worse, dozens of singleton classes chock full of variables. Speaking of singletons, I recently worked on some code where the original developer had create a factory class that produced exactly one and only one instance. Yes, it was "object" oriented, but the code would have been cleaner and made a whole lot more sense had they just written it in C.)

          OriginalGriffO L 3 Replies Last reply
          0
          • J Joe Woodbury

            It's less confusing that where the developer uses classes at an absurdly granular level and/or buys into the "a method should do only one thing" nonsense. Then there's the one person who uses "var" for every definition in their C# code. The solution is to write aesthetically pleasing code will with meaningful names. In the C++ world, using static properly is a big help. (One thing that cracks me up are devs who criticize global variables and then create a singleton class full of variables. Or, worse, dozens of singleton classes chock full of variables. Speaking of singletons, I recently worked on some code where the original developer had create a factory class that produced exactly one and only one instance. Yes, it was "object" oriented, but the code would have been cleaner and made a whole lot more sense had they just written it in C.)

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

            Joe Woodbury wrote:

            Then there's the one person who uses "var" for every definition in their C# code.

            I'm just glad var is shorter and easier to type than dynamic.... :sigh: I'm betting that is going to bite us in a couple of years time.

            The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

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

            K B S 3 Replies Last reply
            0
            • M Mohammed Hameed

              It has been noticed that some developers heavily use Global variables, may be without any discomfort. Is it like they get accustomed to it and hence use it? Dont they get confused by over usage?

              Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!

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

              If there are too many, by definition (of "too") that is bad. Similarly for "over usage".

              1 Reply Last reply
              0
              • J Joe Woodbury

                It's less confusing that where the developer uses classes at an absurdly granular level and/or buys into the "a method should do only one thing" nonsense. Then there's the one person who uses "var" for every definition in their C# code. The solution is to write aesthetically pleasing code will with meaningful names. In the C++ world, using static properly is a big help. (One thing that cracks me up are devs who criticize global variables and then create a singleton class full of variables. Or, worse, dozens of singleton classes chock full of variables. Speaking of singletons, I recently worked on some code where the original developer had create a factory class that produced exactly one and only one instance. Yes, it was "object" oriented, but the code would have been cleaner and made a whole lot more sense had they just written it in C.)

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

                Joe Woodbury wrote:

                person who uses "var" for every definition in their C# code

                Put "using var = System.Int32;" in their code :)

                1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  Joe Woodbury wrote:

                  Then there's the one person who uses "var" for every definition in their C# code.

                  I'm just glad var is shorter and easier to type than dynamic.... :sigh: I'm betting that is going to bite us in a couple of years time.

                  The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

                  K Offline
                  K Offline
                  Keith Barrow
                  wrote on last edited by
                  #12

                  Only if you use it.

                  “Education is not the piling on of learning, information, data, facts, skills, or abilities - that's training or instruction - but is rather making visible what is hidden as a seed”
                  “One of the greatest problems of our time is that many are schooled but few are educated”

                  Sir Thomas More (1478 – 1535)

                  OriginalGriffO 1 Reply Last reply
                  0
                  • M Mohammed Hameed

                    It has been noticed that some developers heavily use Global variables, may be without any discomfort. Is it like they get accustomed to it and hence use it? Dont they get confused by over usage?

                    Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!

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

                    When I started learning Java programming in 8th grade, the books only used Global variables, everywhere :doh: even for the loops... That practice continued a long time, unless I learnt what is code! Damn, the books, that teach us wrong concepts in fundamental level

                    1 Reply Last reply
                    0
                    • B BobJanova

                      Well, hamsters' brains aren't that big ... it's cruel enough making them write JavaScript without expecting good JavaScript.

                      R Offline
                      R Offline
                      RaisKazi
                      wrote on last edited by
                      #14

                      Agree, have seen this mostly in JavaScript. :laugh: Every developer declaring their on duplicate(purpose) variables and functions to avoid anger of other developers of causing their code to break. :doh:

                      Change is a pattern of life.

                      1 Reply Last reply
                      0
                      • K Keith Barrow

                        Only if you use it.

                        “Education is not the piling on of learning, information, data, facts, skills, or abilities - that's training or instruction - but is rather making visible what is hidden as a seed”
                        “One of the greatest problems of our time is that many are schooled but few are educated”

                        Sir Thomas More (1478 – 1535)

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

                        I'm not planning to, but the kind of person who habitually defines everything with var because he's too lazy to think about what his classes should be is just going to love a declaration which turns off compile time checking. He can generate four times as much (completely useless and untested) error and warning free code with dynamic in half the time... :sigh: Then it's someone elses problem to pick up the pieces when it all crashes at run time.

                        The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

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

                        V 1 Reply Last reply
                        0
                        • OriginalGriffO OriginalGriff

                          Joe Woodbury wrote:

                          Then there's the one person who uses "var" for every definition in their C# code.

                          I'm just glad var is shorter and easier to type than dynamic.... :sigh: I'm betting that is going to bite us in a couple of years time.

                          The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

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

                          Anyone who declares anything dynamic without a damn good reason should get a slap round the head. It's loose, lazy, unclear and slow. If you know the name of methods that you want to call on an object (which you need to to make dynamic more than just object), you know enough to have it implement an interface and dispatch calls through that.

                          OriginalGriffO M 2 Replies Last reply
                          0
                          • B BobJanova

                            Anyone who declares anything dynamic without a damn good reason should get a slap round the head. It's loose, lazy, unclear and slow. If you know the name of methods that you want to call on an object (which you need to to make dynamic more than just object), you know enough to have it implement an interface and dispatch calls through that.

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

                            The only part of that about which we disagree is the punishment involved. You prefer "slap"; I prefer "baseball bat". I thought it was stupid when they introduced var, while accepting the need when using LINQ. I have yet to see a convincing argument for the very existence of dynamic (and yes, I do Office interop occasionally, and no, I don't use dynamic for it)

                            The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

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

                            V R 2 Replies Last reply
                            0
                            • C Chris Maunder

                              Mohammed Hameed wrote:

                              Is it like they get accustomed to it and hence use it?

                              Or they simply don't understand how to write object oriented and/or well architected code.

                              cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

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

                              This may be a stupid question, but that is the way I learn: Is there an "official" guide to the proper use of global variables, like a Microsoft guidelines document or something?

                              Cornelius Henning ---------------------------------------------- "There is no reason for any individual to have a computer in their home." -- Ken Olson, President of DEC, World Future Society Convention, 1977

                              C M P L 4 Replies Last reply
                              0
                              • OriginalGriffO OriginalGriff

                                I'm not planning to, but the kind of person who habitually defines everything with var because he's too lazy to think about what his classes should be is just going to love a declaration which turns off compile time checking. He can generate four times as much (completely useless and untested) error and warning free code with dynamic in half the time... :sigh: Then it's someone elses problem to pick up the pieces when it all crashes at run time.

                                The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

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

                                I doubt you'll see a lot of lazy devs overusing dynamic, because it takes away Intellisense, and most of those types rely on Intellisense.

                                OriginalGriffO M 2 Replies Last reply
                                0
                                • OriginalGriffO OriginalGriff

                                  The only part of that about which we disagree is the punishment involved. You prefer "slap"; I prefer "baseball bat". I thought it was stupid when they introduced var, while accepting the need when using LINQ. I have yet to see a convincing argument for the very existence of dynamic (and yes, I do Office interop occasionally, and no, I don't use dynamic for it)

                                  The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

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

                                  Quote:

                                  I have yet to see a convincing argument for the very existence of dynamic

                                  I've used it when dealing heavily with JSON data.

                                  1 Reply Last reply
                                  0
                                  • M Mohammed Hameed

                                    It has been noticed that some developers heavily use Global variables, may be without any discomfort. Is it like they get accustomed to it and hence use it? Dont they get confused by over usage?

                                    Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!

                                    V Offline
                                    V Offline
                                    Valery Possoz
                                    wrote on last edited by
                                    #21

                                    I once worked on a project with over 3000 global variables. The "team leader" did not even know what half of them were suppose to be for... He just use to add new ones!! I let you guess the quality of the project! So yes they get confused... :(

                                    M R 2 Replies Last reply
                                    0
                                    • OriginalGriffO OriginalGriff

                                      The only part of that about which we disagree is the punishment involved. You prefer "slap"; I prefer "baseball bat". I thought it was stupid when they introduced var, while accepting the need when using LINQ. I have yet to see a convincing argument for the very existence of dynamic (and yes, I do Office interop occasionally, and no, I don't use dynamic for it)

                                      The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

                                      R Offline
                                      R Offline
                                      Rob Philpott
                                      wrote on last edited by
                                      #22

                                      OriginalGriff wrote:

                                      The only part of that about which we disagree is the punishment involved.

                                      Actually I find it often just best to kill them. Does wonders to calm the nerves.

                                      Regards, Rob Philpott.

                                      1 Reply Last reply
                                      0
                                      • L Lost User

                                        This may be a stupid question, but that is the way I learn: Is there an "official" guide to the proper use of global variables, like a Microsoft guidelines document or something?

                                        Cornelius Henning ---------------------------------------------- "There is no reason for any individual to have a computer in their home." -- Ken Olson, President of DEC, World Future Society Convention, 1977

                                        C Offline
                                        C Offline
                                        Colin Mullikin
                                        wrote on last edited by
                                        #23

                                        You're supposed to try to reduce the number of global variables that you use and only use them when necessary. The second paragraph on Wikipedia[^] gives pretty good reasons for this.

                                        The United States invariably does the right thing, after having exhausted every other alternative. -Winston Churchill America is the only country that went from barbarism to decadence without civilization in between. -Oscar Wilde Wow, even the French showed a little more spine than that before they got their sh*t pushed in.[^] -Colin Mullikin

                                        1 Reply Last reply
                                        0
                                        • B BobJanova

                                          Well, hamsters' brains aren't that big ... it's cruel enough making them write JavaScript without expecting good JavaScript.

                                          C Offline
                                          C Offline
                                          Chris Maunder
                                          wrote on last edited by
                                          #24

                                          I will put my hand up and say loudly and with some shame: Our Javascript sucks

                                          cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                                          R 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