My problem with the nested functions is that it is much harder to get a grasp of what the shared state is -- any local variable in the outer function *could* be part of the shared state, and the only way to tell for sure is by inspecting all the subfunctions.
That would be solved if, instead of marking variables in inner scopes that refer to outer scopes, it were the other way round, and variables in the outer scope were marked as being rebindable in inner scopes.
def f(): rebindable x def inc_x_by(i): x += i # rebinds outer x x = 39 inc_x_by(3) return x
This would only apply to *assignment* from inner scopes, not to *use* from inner scopes, right? (Otherwise it would be seriously backwards incompatible.)
I'm not sure I like it much, because it gives outer scopes (some) control over inner scopes. One of the guidelines is that a name defined in an inner scope should always shadow the same name in an outer scope, to allow evolution of the outer scope without affecting local details of inner scope. (IOW if an inner function defines a local variable 'x', the outer scope shouldn't be able to change that.)
--Guido van Rossum (home page: http://www.python.org/%7Eguido/)