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

Re^4: 'require/use' scoping ("scope")

by tye (Cardinal)
on Jan 29, 2008 at 17:52 UTC ( #664935=note: print w/ replies, xml ) Need Help??


in reply to Re^3: 'require/use' scoping ("scope")
in thread 'require/use' scoping

I guess you need to scour the web and literature and implement your new personal definition of "scope" (which appears to only include "lexical scope of variables").

For example, Wikipedia knows that there are non-lexical types of scope including dynamic scope, that scope can apply to values not just variables, and that "a namespace is a scope". Although Foldoc unfortunately defines scope tersely in a way that implies only lexical scopes but this poor definition is contradicted by its own entries for dynamic scope and lexical scope.

A namespace is a scope and it does limit the effect of a variable; that's the point. You don't want your choice of variable names to affect the code that doesn't use your namespace. A package variable is limited in scope to only places that reference the owning namespace (either by declaring that they are in that package or by prepending the package name in order to access the variable). You can even access lexical variables outside of their scope if you take extra steps. The scope talks about where a simple $name will work.

local has nothing to do with the scope of the variable. It deals with the value

Yeah, that was what I said. But it is more accurate to say that local effects a new instance of a variable (and assigns that instance a new value) that has a dynamic scope. The value of this new instance can be changed but the instance will be destroyed when the program leaves its dynamic scope.

Update: Brian, think what you want. I heard about dynamic scope because the transition from Perl 4 to Perl 5 was a transition from only supporting dynamic scope to supporting lexical scope. If the authors of some of the Perl documentation now choose to not use "scope" except when talking about lexical scope, then I don't have a problem with that. But the programming world is not the Perl documentation and claiming "a namespace isn't a scope" is untrue. You can claim "the Perl documentation avoids referring to a namespace as a scope, preferring to reserve that term for only lexical scopes". But you don't get to define what the word "scope" means outside of that little world. You can even say "I wouldn't call a package a scope". I don't happen to live in the Perl documentation and care about more than how such chooses to use words.

You can choose to use a more narrow definition of "scope" and you won't even run into any problems so long as you realize you have narrowed the definition and so avoid boldly declaring what isn't included in your narrowed definition (without qualifiers to denote to others that it is a non-standard usage).

- tye        


Comment on Re^4: 'require/use' scoping ("scope")
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2014-08-21 18:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (141 votes), past polls