Python handles globals badly.

Ian Kelly ian.g.kelly at
Wed Sep 2 21:38:01 CEST 2015

On Wed, Sep 2, 2015 at 12:47 PM,  <tdev at> wrote:
> Using the keyword global inside each(!) function only
> to mark the global var writeable in each of the functions
> is really an over-regulation and very annoying from my point of view.

To me, marking a variable as global in a large number of functions is
a code smell that indicates that you're probably overusing globals.
Lua is an example of a language that takes the opposite approach: in
Lua, every variable is global unless you explicitly mark it as local.
Lua is a fine language overall, but that is one of my pet peeves with
it as it is all too easy to fall into the trap of neglecting to mark
your local variables, and then you end up with too many global
variables and a disaster of a code base.

> Especially cause a module is a singleton.
> And globals are only module aware vars.
> Even Java (type-safe language) need not such things for its static or member vars.

Because Java has static typing. It can determine that a variable is
static simply by observing that the variable is declared as such in
the class and isn't declared in the function.

Would you prefer to have to declare all your local variables as
"local" just so that you don't have to explicitly declare the (few, I
hope) global ones?

More information about the Python-list mailing list