[Python-Dev] Explicit Lexical Scoping (pre-PEP?) (original) (raw)

Guido van Rossum guido at python.org
Wed Jul 5 19:27:41 CEST 2006


On 7/5/06, Michael Chermside <mcherm at mcherm.com> wrote:

Guido writes: [discussion of how to fix the can't-bind-outer-scope-vars wart] > I think we have to continue to search for a solution that extends the > idea of global declarations. > > I've proposed extending its meaning to refer to the nearest outer > scope where the variable is set; if there is no such scope it's an > error. This will break a small number of program but probably not very > many; still, it'll require a future statement or waiting until Python > 3.0. The downside is that "global" is not a very intuitive word for > this new meaning.

I disagree with your last statement -- I think "global" is a very intuitive word for this. As I understand it, in programming "global" has two meanings, closely intertwined. One is "universal, same throughout the system". For instance, "The singleton pattern is used to create a single, global instance of a type." The second meaning is the term "global variable". This term developed (I believe) in languages that had only two scopes: local-to-current-function and global-to-entire-program. But the term "global variable" refers to any variable whose assignment is a "side effect", regardless of whether that variable is global-to-entire-program, global-to-module, or even global-to-enclosing-function. I have even heard the term "global variable" (mis)used to refer to any kind of side effect. Anyhow, in Python only builtins is really global -- even today's global keyword only refers to module scope. So I believe that it would be a very reasonable interpretation of "global" to mean "not local", and implement as "search enclosing scopes in order to find the binding".

I really wish I could agree with you, because that would make the choice so much easier.

However I still don't believe "global" has the stretchiness in its meaning that you claim it has. Have you ever heard a Python programmer talking about closures use the word "global variable"?

Are there any other native speakers who side with Michael?

-- --Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list