Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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.

Comment on Re: Global or not global
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 (Deacon) 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?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (15)
As of 2015-05-06 18:55 GMT
Find Nodes?
    Voting Booth?

    In my home, the TV remote control is ...

    Results (143 votes), past polls