non-implicit globals -- missing feature
aleax at aleax.it
Tue Jun 17 18:25:53 CEST 2003
Helmut Jarausch wrote:
> Ofcourse one wouldn't forbid all global names but you would be
> forced to "declare" them. If I remember right, Modula requires
> an 'import <Name>' statement to access non-local names.
I think you remember incorrectly: Modula-2 requires a MODULE
to import names from OTHER MODULES -- just like Python
does; it does *NOT* require every single PROCEDURE to
re-import all over again all the global names its module has
already imported...!!! I think that would make it unusable.
In Python it would be even worse. With Python's simple name
lookup mechanism, built-ins are looked up as "non-local names"
just like any other: do you think it might be remotely acceptable to
force any function that e.g. wants to loop five times to *declare*
it's going to use nonlocal name 'range' before it can say
for i in range(5):
....?! If you do, then it seems clear to me that the level of
"boilerplate" (declarative, repetitive redundancy) that you're
most comfortable with is many light-years away from what
Python offers you: I would therefore, albeit reluctantly, feel
it best to suggest to you that you look for other languages,
which do force you into such abundant declarative boilerplate:
Python's about getting AWAY from it. I doubt you'll find what
you're looking for in Modula-2 (it's NOT as restrictive as you
would wish it to be!), but people who are truly obsessed with
forcing programmers to use always more and more redundant
declarative boilerplate may no doubt have developed languages
which are even more constraining in this regard.
> I still think this automatic usage of global names together with a
> copy on write semantics is error-prone.
A "copy on write semantics" no doubt might be, but that's
utterly different from what Python offers, so I don't see why
that should be relevant. In Python, any name you rebind
locally is local (unless a 'global' statement says otherwise
explicitly); any other name you access but never rebind is
looked up lexically (in outer functions, then up to the module
level, then into built-ins).
> Many thanks for your comment and especially this hint,
More information about the Python-list