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

Re: Global or not global

by moritz (Cardinal)
on Jul 03, 2012 at 06:29 UTC ( #979594=note: print w/replies, xml ) Need Help??


in reply to Global or not global

(singleton = global variable)?

It is global state that is a problem, not just global variables. And yes, singletons are also global state. So you win nothing by using a singleton over a global variable.

So you have several options: you can understand why global state is bad, and still decide to use it. Or you can go the OO route where the database handle is available.

Replies are listed 'Best First'.
Re^2: Global or not global
by tobyink (Abbot) on Jul 03, 2012 at 10:14 UTC

    Indeed - global variables are a symptom of the underlying design problem, they're not a problem in themselves.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re^2: Global or not global
by BillKSmith (Priest) on Jul 30, 2012 at 02:41 UTC

    In this case, I reluctantly vote for the global solution. The required object code would probably include most of the program so object variables would be little different than globals. The increase in code complexity would cancel any small improvement in encapsulation.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://979594]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2016-12-02 22:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (51 votes). Check out past polls.