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

Re: best practice

by hsmyers (Canon)
on Aug 27, 2001 at 19:50 UTC ( #108155=note: print w/ replies, xml ) Need Help??


in reply to best practice

The way I remember it, locals versus globals and a heap of other ideas more or less came into being along with the 'Structured' revolution. If you want a good (possibly best) introduction to some of the pre-object ideas, you can't do much better than Structured Design by by Ed Yourdon and Larry Constantine (Prentice Hall/Yourdon Press, 1978.) And for an honest and funny appraisal see Ed Yourdon's self-review.

More current thinking (i.e. oo) would say that variable scoping is tied to the idea of information hiding. In a kind of paranoid fashion, the goal is two (at least 2) fold, first, don't let anyone see object information that they have no 'need to know' clearance for. Second if they really, really, really must muck with your stuff, at least insulate that with the usual get/set pair (publish through a controlled interface.) More to the point, globals violate the hell out of these ideas—hence the bad reputation! On a real world basis, you can obviously do whatever you want, but it is usually better practice to avoid global scope, only using them when there is a clear need for same. My usual excuse comes from code optimization, stuffing a variable on the stack when I need to call a function, takes time so if time is crucial I make the needed stuff global. I'd point out here that if speed is a concern, you most likely wouldn't be using Perl anyway, more like assembler or C!

hsm


Comment on Re: best practice
Re: Re: best practice
by dragonchild (Archbishop) on Aug 27, 2001 at 19:59 UTC
    To harp on something here ... 99% of the time optimizations are done, it's usually a case of premature optimization.

    The basic rule of thumb is that if you cannot back up your desire to optimize with hard data, then DON'T! You will make your code completely unmanageable, usually for only a few micro-seconds of gain - completely unnoticeable to the user.

    ------
    /me wants to be the brightest bulb in the chandelier!

    Vote paco for President!

      Clearly your mileage may vary, but the difference between inner loops written in 'C' or higher compared to assembler (and optimized assembler at that) is way significant if you are talking about number crunching. Typically I sin in such a fashion when I'm generating fractals and such like. Being greedy, I will use any trick I can in order to bitblit a little faster!

      hsm

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2014-12-26 18:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (174 votes), past polls