Does not Developers get confused if there are too many global variables?
-
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 ofdynamic
(and yes, I do Office interop occasionally, and no, I don't usedynamic
for it)The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
-
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!!!
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... :(
-
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 ofdynamic
(and yes, I do Office interop occasionally, and no, I don't usedynamic
for it)The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
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.
-
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
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
-
Well, hamsters' brains aren't that big ... it's cruel enough making them write JavaScript without expecting good JavaScript.
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
-
I was overused once, it did cause discomfort, but I was never confused!
“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)
You lucky, lucky bastard. (bonus points if you name that movie)
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
-
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.
Most of 'em don't bother with AnySense! :laugh:
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
-
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
Thanks Chris. Yes, that would be the case.
Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!
-
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
There is a nice discussion here on Cunningham's site http://c2.com/cgi/wiki?GlobalVariablesAreBad
Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!
-
I was overused once, it did cause discomfort, but I was never confused!
“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)
Thanks for your input. So its like discomfort for some and confusion for some developers.
Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!
-
Global variables are widely recognised to be a Bad Thing and confusing. That's why programming languages have gradually introduced more and more ways of avoiding them: local variables, function parameters, structures (to wrap up multiple parameters where there would be a confusingly large number of them), encapsulation, closures ... I'm sure there are other features that essentially come down to reducing the scope within which a data object is visible to avoid confusion.
Thanks Bob. Very good explanation. :thumbsup:
Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!
-
You lucky, lucky bastard. (bonus points if you name that movie)
cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
Life of Brian.
Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!
-
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.
Yes, prefixing them may reduce much confusion. Thank you.
Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!
-
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.
Agreed.
Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!
-
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
Here it is:
- Don't use global variables.
- If you thing you have found a reason to use a global variable, you're wrong. Just don't.
Of course, synchronized singletons and read-only monostates are not 'real' global variables. Also, if you're writing C and you have a variable that allows access to a hardware device, it may be forgiven. JM2B,
Pablo. "Accident: An inevitable occurrence due to the action of immutable natural laws." (Ambrose Bierce, circa 1899).
-
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.
Superb...
Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!
-
Life of Brian.
Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!
-
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... :(
Thanks for the real time scenario.
Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!
-
Ding! 10 points to Mr. Hameed!
- I would love to change the world, but they won’t give me the source code.
Thanks :)
Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!
-
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.)
Not that I am particularly defending the use of var, but I quite like it in the case of
var foo = new SomeReallyQuiteSensibleButLongName();
especially if there are a few of them (cuz they line up and look nice) You can see what the type is easily, so no harm done. When it is
var foo = TheResultOfSomeFunctionWhoseNAmeDoesntReflectItsReturnType();
it annoys me as I have to use intellisense to ind out what type it is. Especially annoying with something like
var selectedCustomer = GetCustomerFromList();
which, at first glance, I would guess at selectedCustomer being some kind of Customer object. Imagine my surprise when I find out it is a boolean! Yep - the function returns a boolean that determines whether the customer was selected from the list. Now this comes down to good naming - and I have yet to meet a developer that names consistently well (myself included)
MVVM # - I did it My Way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')