Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://759064]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2018-07-16 03:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (330 votes). Check out past polls.

    Notices?