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

Re^3: Are global variables "bad"?

by DStaal (Chaplain)
on Apr 21, 2009 at 17:32 UTC ( #759064=note: print w/replies, xml ) Need Help??

in reply to Re^2: Are global variables "bad"?
in thread Are global variables "bad"?

I don't actually see any particular reason to use a singleton in this case: You are parsing a file, and want to store it someplace. There is no particular reason (from what you've said) why parsing a different file, or even reparsing the file should be prevented. (Besides the fact of memory useage/speed, which to me isn't a reason for a singleton, just a reason to keep using the same object.)

Basically, it's extra complexity to prevent future uses. I don't see why either would be something you want.

Replies are listed 'Best First'.
Re^4: Are global variables "bad"?
by Porculus (Hermit) on Apr 21, 2009 at 19:38 UTC

    Agreed. The singleton is, when you get right down to it, really just a hack to add global variables to Java in an "object-oriented" way, dignified with a fancy name and notable mainly for being the design pattern people are by far the most likely to be able to remember off the tops of their heads.

    There are very few cases where singletons add value in a language like Perl. If your code is worth the effort of moving away from global variables, it's worth the effort of generalising completely (for example, allowing people to have multiple data sets open at once).

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2018-10-23 09:39 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (125 votes). Check out past polls.