Op 2005-10-05, Duncan Booth schreef <[EMAIL PROTECTED]>: > Paul Rubin wrote: > >> Brian Quinlan <[EMAIL PROTECTED]> writes: >>> Have those of you who think that the lack of required declarations in >>> Python is a huge weakness given any thought to the impact that adding >>> them would have on the rest of the language? I can't imagine how any >>> language with required declarations could even remotely resemble >>> Python. >> >> What's the big deal? Perl has an option for flagging undeclared >> variables with warnings ("perl -w") or errors ("use strict") and Perl >> docs I've seen advise using at least "perl -w" routinely. Those >> didn't have much impact. Python already has a "global" declaration; >> how does it de-Pythonize the language if there's also a "local" >> declaration and an option to flag any variable that's not declared as >> one or the other? > > The difference is that perl actually needs 'use strict' to be useful for > anything more than trivial scripts. Without 'use strict' you can reference > any variable name without getting an error. Python takes a stricter > approach to begin with by throwing an exception if you reference an > undefined variable. > > This only leaves the 'assigning to a different name than the one we > intended' problem which seems to worry some people here, and as has been > explained in great detail it incurs a cost to anyone reading the code for > what most Python users consider to be a very small benefit.
It also is one possibility to implement writable closures. One could for instace have a 'declare' have the effect that if on a more inner scope such a declared variable is (re)bound it will rebind the declared variable instead of binding a local name. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list