|Think about Loose Coupling|
Re^3: Global variable vs passing variable from sub to subby Wassercrats
|on Sep 14, 2004 at 21:32 UTC||Need Help??|
I won't read through the tutorials to learn what that last line does. I recognize all the operators, but can't be sure what it does without looking stuff up. The use of "&&" confuses me. It looks like some boolian structure that I used to know how to use, or maybe it's an ordinary logical "and", but I'd like to see parentheses in that case because I never remember the order of operations of things.
I recognized the hash, but I'm unsure about the the use of "exists". I guess it's being used for the 1 or 0 value, but I don't think that's how it's usually used. I wouldn't use hashes when teaching something not related to hashes. I've only used them once when I wrote Varstructor, which had to parse code that might contain hashes, and maybe another time for that duplicate elimination trick.
In the second block of code, I just didn't get the point. Maybe I didn't try hard enough, but a better explanation would have helped.
No matter what code you use in an example, it helps to explain what it does.
After I posted that reply I realized that might the person's point, but he mentioned having to step through the code with a debugger, which wouldn't be necessary. Is it really so hard to search the code for the variable in question? Even Wordpad, which I'm still using for now, could do that. With globals, you don't have to check to see if you passed the value on to another routine. You merely search for a variable by name.
As I mentioned in another thread, if you change plans and want to call a variable that was lexically scoped a few routines ago, things get complicated.
I find the arguments in this thread to be lacking substance. The effort it takes to properly scope variables, which often requires a different code structure, outweighs the problems I've encountered using globals. Globals mean less planning ahead, EASIER debugging, and, using the definition of "safe" that people have used with me, safer code.