block scope?

Paul Rubin http
Sat Apr 7 00:40:59 EDT 2007


John Nagle <nagle at animats.com> writes:
>     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.

I think Perl did this pretty good.  If you say "my $i" that declares
$i to have block scope, and it's considered good practice to do this,
but it's not required.  You can say "for (my $i=0; $i < 5; $i++) { ... }"
and that gives $i the same scope as the for loop.  Come to think of it
you can do something similar in C++.



More information about the Python-list mailing list