Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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
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 (Curate) 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 musing on the Monastery: (2)
As of 2015-11-28 07:42 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (739 votes), past polls