in reply to best practice
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: best practice
by dragonchild (Archbishop) on Aug 27, 2001 at 19:59 UTC | |
by hsmyers (Canon) on Aug 27, 2001 at 22:03 UTC |