Re: Namespace vs. Scope
[email protected] (John Porter)
| Newsgroups | perl.trainers |
|---|---|
| Message-ID | <[email protected]> |
Jonathan Feinberg wrote: > My students caught me off guard when they pointed out that sometimes I use > the word "scope", as when I'm discussing my(), and that sometimes I use the > word "namespace", as when I'm discussing packages. Talk about global variables: they are like files in a hierarchical filesystem, in that their names, if fully qualified, have "paths"; and also analogously, they're accessible from anywhere, at any time (as files are). Globals (sometimes aka "package" variables) are truly global; namespaces only exist to bring some organization. Imagine if all your files had to sit in a single directory... "Scope", in non-programming contexts, has to do with visibility; and that's one of the things that distinguishes lexical variables. Their visibility -- and hence accessibility -- is determined by the lexical structure of the program. (Of course, unlike static langauges like C, this is not strictly true, because the data structure of a lexical can survive beyond its "native" scope, since perl uses reference-counting. But that's a slightly more advanced concept.) You might want to talk about how perl variable names are just pointers, or references, to the real variable thingy, unlike C where a name is an alias for the memory location of the variable. -- John Porter So take a pointed stick and touch Piggy's eyes He's gonna turn and leave you a big surprise