Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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 (Vicar) 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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2017-09-23 07:33 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (272 votes). Check out past polls.