Creating a local variable scope.

markolopa marko.loparic at gmail.com
Tue Dec 1 17:32:25 EST 2009


Hi Roger,

> > That is what I do regularly...8->
>
> Well really dude, you need to stop doing that. It's not a language
> problem, it's a memory problem (human not RAM!).

You guessed quite correctly!...:-) I can't recognise my code sometimes
after a single week. That's why I spend a lot of time cleaning it to
be easy to get back. Fortunately it seems to be recognised as a good
practice...

> You need to be aware of
> what you're putting into your namespace. This is one of the reasons
> people try to avoid using global variables, if you forget you've used a variable name and use it again somewhere you get an undefined state and
> hours of debugging / data loss / subtle corruptions you won't spot until
>  the backups have all been cycled etc.

Sure, zero global variables in my programs.

> I'm surprised you have a recurring problem with this really. My memory
> is terrible and I reuse variable names all over the place without any
> trouble. Maybe try keeping the length of your functions down so that
> they fit on a single screen and create and use a strong naming
> convention i.e.
>
> Long, descriptive variable names all_in_lower_case
> Function names all in CamelCase
> Global names are in ALL CAPS

yes, pep8 I guess.

> Loop variable names all prefixed with 'each_'

Interesting. A radical idea (and not very elegant for my taste I would
say) but it could certainly make me avoid such bugs...

Cheers!
Marko



More information about the Python-list mailing list