Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Are global variables "bad"?

by eric256 (Parson)
on Apr 21, 2009 at 18:40 UTC ( #759081=note: print w/ replies, xml ) Need Help??


in reply to Re: Are global variables "bad"?
in thread Are global variables "bad"?

I like the singleton idea. I've used it for DBI connections and config files and it makes it easy to have global behaviour without the downsides of having global variables. At least thats how I see it.


___________
Eric Hodges


Comment on Re^2: Are global variables "bad"?
Re^3: Are global variables "bad"?
by gwadej (Chaplain) on Apr 21, 2009 at 18:56 UTC

    After having worked with code that had made extensive use of Singletons, I think I would have to disagree. I'd say that Singletons have all of the advantages of global variables with all of the disadvantages of globals.

    The only advantage I've seen is in grouping a set of variables (or behavior) into one Singleton object, instead of scattering them around. But, you can do that without Singletons, as well.

    I try to avoid Singletons, because they've been the source of lots of trouble for me.

    On the other hand, in a standalone script global variables can often simplify the code. The practice does tend to put an upper limit on how much the code can safely do.

    G. Wade

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://759081]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-09-18 23:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (126 votes), past polls