Namespace model

Jurjan-Paul Medema jurjanm at c.ict.om.org
Fri Dec 8 19:54:03 CET 2000


Hello all,

I like many features of Python's unique language design a lot 
(since I first started studying and using it last summer). But what 
bothers me, is the whole Namespace model that is so unlike a 
traditional scope model. Fact is that I am not happy with it. I am 
sure there has been a lot of discussion about this during the last 
10 years, and therefore I hope that somebody can clarify it to me.

Especially in functional programming it is common place to nest 
functions. The FAQ answers the question how a nested function 
can access a parameter to the parent function by having the same 
parameter repeated as a default parameter (FAQ4.5). This I find at 
least more acceptable than the alternative that requires the 
introduction of a completely new object class, because to me that 
is too remote from the original idea. However this becomes the only 
possible way of getting around things when you want the nested 
function to be recursive (again: this is common place in functional 
programming). I have already encountered a situation where I 
needed to pass a function as a parameter to a standard Python 
Module, where I needed recursion with more than one parametere, 
but also had to comply with a set function signature. It took quite 
some redesign to come up with a working OO-model, that turned 
out to be bigger than I thought should be necessary. 

I am not going to bother you with that example, but this is an 
abstract version:

# 'operation_A', 'operation_B', 'operation_C' and 'operation_D'
# can be anything in this example.
# (At least) 'operation_C' returns a pair of values.

def foo(x) :

	def bar(y, i) :
		if y : return operation_A(y, i)
# the following 'bar' is not found in the namespace.
           else : return operation_B( bar( operation_C(y, i) ) )  

	z = bar(x, 0)
	return operation_D (x, z)

Here Python simply lacks the intuitivity that it promises. I like OO, 
but I also like to keep functions together that really belong together 
(on a different level than a class level obviously).

I would like to ask Guido, but if anybody has a good idea, please 
explain to me why Python was designed with the Namespace 
model instead of a normal scope model!!
It can't be that it's jsut because this keeps the interpreter/compiler 
simpler or is that all that it is?? Can we expect this to be resolved 
in future versions of Python or is this how it always will be...?

Seriously, I don't think a language that claims to be designed for 
educational purposes should contain something this inconsistent: 
you either support function nesting or you don't, but this is just half-
hearted.
Please clarify, somebody!
 
And yes, I honestly do like Python a lot, so I hope I do not come 
across as grumbling too much... 

Thanks,
Jurjan-Paul Medema




More information about the Python-list mailing list