|
It has been noticed that some of the developers knowingly/unknowingly use many global variables. But in my view, naturally they should feel confused at sometime, still some of them dont reveal the fact may be.
Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!
|
|
|
|
|
Well I'm confused by your two sentences. Does that help?
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
I mean: dont they get confused if they over use Global variables?
Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!
|
|
|
|
|
|
I too dont know. It would be great if I get some discussion on this to get more clear picture.
Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!
|
|
|
|
|
This isn't the place for such discussions - look at the top of the page.
"This forum is purely for amusement and discussions on code snippets."
For a more serious discussion (ish) try the lounge. But I'd suggest that you phrase it a little differently:
"Do you get confused if there are too many global variables?" is a lot clearer.
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
Ok, thanks.
Understand SOLID! Believe SOLID! Try SOLID; your Code becomes Rock SOLID!!!
|
|
|
|
|
Mohammed Hameed wrote: But in my view, naturally they should feel confused at sometime, still some of them dont reveal the fact may be.
I don't understand that sentences.
Mohammed Hameed wrote: It has been noticed that some of the developers knowingly/unknowingly use many global variables.
Well, in 99,9% of all my actual project have no global variable. I write OOP so there is no need, except when I like to have one to offend my collegues.
Author of Primary ROleplaying SysTem
How do I take my coffee? Black as midnight on a moonless night.
War doesn't determine who's right. War determines who's left.
|
|
|
|
|
Thank you for discussing on this topic.
I mean to say: Most of the developers who over use global variables, at some point in time, while development get confused whether to use them or avoid. Some of them may never reveal to others about this confusion.
http://authenticcode.com
|
|
|
|
|
Ah! Ok. Now I got it.
Well, yes. Like everything that is abbused, a lot of global variables can make your day a little bit harder. I'm not one of those "Don't use global variables ever", I'm more of the kind saying. "Don't use global variables ever, when there is an alternative." Oh. I just realized. It's the same.
Author of Primary ROleplaying SysTem
How do I take my coffee? Black as midnight on a moonless night.
War doesn't determine who's right. War determines who's left.
|
|
|
|
|
Perfect. Thanks.
http://authenticcode.com
|
|
|
|
|
Correct. Global variables can cause confusion. Therefore developers should avoid them.
It is all about the readability of code: If you call a function, and it calculates a return value based on the current value of a global variable, the only way to realize this dependency is to read and understand the function code. Without that knowledge, you may expect that every time you call that function you get the same value. But if you pass that 'global' value as a parameter to the function, then it will be obvious what the function depends on, just by looking at the interface.
Understanding code with global variables takes a lot more time than understanding code without global variables.
|
|
|
|
|
Agreed...
My Reading-o-Meter
Previous -> Read "CLR via C#" by Jeffrey Richter.
Current -> Exploring WCF thru Apress' "Pro WCF" by Chris Peiris and Dennis Mulder.
Next -> Need to read "The Art of Computer Programming" by Donald E. Knuth.
My blog - My recent article
|
|
|
|
|
I was looking at some legacy code that I re-wrote for a project and found this gem. There were also variables named bob, mike, jane etc...
string hi;
if(true)
{
hi = "hi";
}
else
{
hi = "hi";
}
|
|
|
|
|
... or a test for 'unreachable code detected' feature of the compiler...
Seulement, dans certains cas, n'est-ce pas, on n'entend guère que ce qu'on désire entendre et ce qui vous arrange le mieux... [^]
Joe never complained of anything but ever did his duty in his way of life, with a strong hand, a quiet tongue, and a gentle heart [^]
|
|
|
|
|
I have decided to write a compiler that handles a robotic arm to slap the developer when this kind of code is fed to it.
|
|
|
|
|
What if the robot became very picky on which code is right? What if it start to slap everyone even his master and creator and then go on a slap-kill spree? Be careful or you may create a machine that will kill us all!
|
|
|
|
|
|
+5
|
|
|
|
|
That reminds me of an idea I had at our office - extended validation using a keyword capable of administering mild electric shocks every time a user does something like use a "." in a text field they can't be bothered to fill in.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
I have a 200kg capable anthropomorphic robot in the basement I can lend it to you, don't hesitate to ask for it, of course given the fact you will allow me to use it before some times...
Please, put a MadSlapMode in the software in which the robot will start slapping everyone at a fast pace without even making a single question.
|
|
|
|
|
Member 9704383 wrote: There were also variables named bob, mike, jane etc.
That's good to write readable code. Bob, short for Robert, meaning: "bright fame". So it's a variable used as a loop counter.
Jane has the meaning of "God is Great" it's used for holding global program-status.
Everybody knows that someone with the name mike drinks to much alcohol. So it's used for error-handling.
The meaning of Jina is "named child", so child-objects are called that way, while root-objects are called adam and an objects that controls other objects is called eve.
If you use those variable-names, everyone knows the meaning.
Author of Primary ROleplaying SysTem
How do I take my coffee? Black as midnight on a moonless night.
War doesn't determine who's right. War determines who's left.
|
|
|
|
|
The best function I had was. It was in VBA, so translated to C#
public void ApriTiQuandoTiDicoIo()
{
...
}
It's Italian for "OpenWhenITellItToYou()", and it did exactly that: Open a File only when I (the developer) wants it.
The signature is in building process.. Please wait...
|
|
|
|
|
Maybe you should smoke tobacco instead of marijuana
|
|
|
|
|
While looking into some production issues and after much looking into the few functions that span over 700-1000 lines, I stumbled upon the root cause. Oh my what a priceless gem!
private static int somefunction(some params)
{
int iKey = -1;
try
{
}
catch (SqlException ex)
{
return iKey;
}
catch (Exception ex)
{
return iKey;
}
finally
{
}
return iKey;
}
|
|
|
|