Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: NEVER do this. Ever. Not even once.

by perchance (Monk)
on Jul 30, 2001 at 18:45 UTC ( #100886=note: print w/ replies, xml ) Need Help??


in reply to NEVER do this. Ever. Not even once.
in thread Variable Scope

Care to explain why?
For quite a long time (before we started Object-Orienting the project) we used global (::) variables to hold our internal database. Though I can understand why under certain circumstances it might not be wise, to that end we found it appropriate.(And there were mounds of vars there).
In fact, I have often found myself looking around in other people's code, trying to figure out which of the hundreds of hashes, arrays and scalar defined at the beginning of the script (outside the scope) they were referring to, and where they were changed. At least when they were ::'ed I knew I had to go chase them...
I appreciate the problems this can cause across packages, but sometimes your scripts standalone.

If I am missing something - please tell me,
--- perchance


Comment on Re: NEVER do this. Ever. Not even once.
Re: Re: NEVER do this. Ever. Not even once.
by chromatic (Archbishop) on Jul 31, 2001 at 04:02 UTC
    I understood dragonchild to mean that using $::somevar is an awful practice. I quite agree. What's the point of telling Perl, "I want you to alert me to potentially hazardous programming" when you go out of your way to violate it?

    As for global variables, they're hard to track down, they can have unfortunate side effects, they can make your code difficult to follow, they break encapsulation, they reduce reusability, and they can lead to severe contortions when you add new things.

    That's not to say that they're forbidden. bikeNomad points out a place where it's absolutely necessary. It's even useful.

    It's just that, in general, the places where you really need to use global variables are few and far between. Appropriately scoped lexicals exist for a reason.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-12-27 15:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls