block scope?

John Nagle nagle at animats.com
Sat Apr 7 00:30:05 EDT 2007


Paul Rubin wrote:
> James Stroud <jstroud at mbi.ucla.edu> writes:
> 
>>Probably, with good code, block scope would be overkill, except that I
>>would welcome list comprehensions to have a new scope:
> 
> 
> Block scope is a win because it gets rid of the uncertainty of whether
> the variable is used outside the block or not.

    In a language with few declarations, it's probably best not to
have too many different nested scopes.  Python has a reasonable
compromise in this area.  Functions and classes have a scope, but
"if" and "for" do not.  That works adequately.

    Javascript got it wrong.  They have declarations, but the default,
in the absence of a declaration, is global, not local or an error.
Bad design.  It's a result of retrofitting declarations to a language,
which usually has painful aftereffects.

					John Nagle



More information about the Python-list mailing list