Nested scopes: why is it weird?

Paul Prescod paulp at ActiveState.com
Sun Sep 9 20:11:12 EDT 2001


Chris Barker wrote:
> 
>...
> 
> I think this would be a nightmare for code maintainance and simple
> syntax. How often do you use a simple variable name like "i" for an
> index? would you really want to use i in one scope, and then inner_i in
> the next, and then inner_inner_i?

How deeply do you nest scopes do you typically have in your Python
programs? Remember that class scopes don't count so you're talking about
a global for-loop *and* a function for-loop *and* a function within a
function for-loop all using the same index variable. This is incredibly
unlikely.

> And as soon as you re-arranged your code a little, you would have to
> re-name a bunch of stuff. I like the current scheme just fine.

It is not as if you can just move code around without looking at the
context anyhow. If you move the code around in the same file then you
are very unlikely to run into this problem because you will already have
avoided the names of global variables. If you move the code around to
another file, it is still unlikely but not quite so much. Nevertheless,
moving code between files often requires renaming variables if only
references to global variables and functions.
-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.ActiveState.com/pythoncookbook




More information about the Python-list mailing list