[Python-ideas] nonlocal functions

Nick Coghlan ncoghlan at gmail.com
Wed Oct 21 13:50:13 CEST 2009


Masklinn wrote:
> On 20 Oct 2009, at 20:23 , Stefan Behnel wrote:
>> Masklinn wrote:
>>> On 20 Oct 2009, at 19:55 , Stefan Behnel wrote:
>>>> And how often would you forget to declare a variable that way?
>>>>
>>> Never.
>> :) Had a good laugh on that one, thanks!
> Why? It's a very simple process: "I'm creating a binding" matches to a
> let. Plus the runtime could easily warn you in the rare cases where
> you'd forgotten a let.
> 
> I can assure you it's not a very difficult habit to pick.

I'm with Stefan in laughing at the idea of someone never forgetting a
variable declaration, and I've done a *lot* of programming in statically
typed languages (and "let" really isn't that different from a type
declaration).

You're also omitting consideration of the ways *other* than assignment
to bind a name in Python (i.e. def, with, except, for). Would those
require an explicit let as well? If not, why single out assignment as a
special case that requires an explicit declaration of "Yes, I really do
want to create a new local here"? If yes... then whatever language
you're dreaming of there, it is getting a really long way away from
Python and giving up one of the major benefits of dynamic typing (i.e.
no need for variable declarations).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------



More information about the Python-ideas mailing list