CRAZY: First class namespaces

Amit Patel amitp at Xenon.Stanford.EDU
Mon May 29 11:37:39 EDT 2000


 Christian Tismer  <tismer at tismer.com> wrote:
| 
| 
| What would be better for the language, dynamic or lexical?
| I really don't know, please tell me your thoughts.
| 

I would find lexical far more useful and less confusing.  Consider
this:


== foo.py ==

import string

def foo(s):
    return string.lower(s)


== test.py ==

import foo

def goo():
    string = "hello"
    print foo(string)

==



With dynamic scoping, foo gets "hello" instead of the string module.
This means I can't write foo properly without knowing every variable
that any caller has used!  And since the callers haven't been written
yet, that's hard.  :)  Alternatively, goo has to know every variable
that is in foo's global scope.  This is also pretty bad because if I
add a new variable to foo.py, everybody has to know.  Note that this
doesn't just affect goo -- goo's caller has to know what's in foo's
scope too!

The same thing applies with nested scopes, but it's easier to show an
example with global scope.

There are very few languages that use dynamic scope anymore.  That's
because lexical scope, although a little harder to implement, is much
more intuitive and allows for modular programming.

	- Amit
-- 
--
Amit J Patel, Computer Science Department, Stanford University
http://www-cs-students.stanford.edu/~amitp/



More information about the Python-list mailing list