Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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.


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 (Chaplain) 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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (15)
As of 2014-10-21 19:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (106 votes), past polls