[Tutor] global is bad but ...

Alan Gauld alan.gauld at btinternet.com
Wed Nov 14 00:11:49 CET 2007

"Dinesh B Vadhia" <dineshbvadhia at hotmail.com> wrote

> Consider a data structure (say, an array) that is operated 
> on by a bunch of functions eg.
> def function_A
>     global array_G

> def function_B
>     global array_G

> etc...

> On the other hand, wiser heads say that the use of 'global' 
> is bad and that reworking the code into classes and objects 
> is better.

Rather than answer your question directly can I ask, do 
you know *why* wiser heads say global is bad? What 
problems does using global introduce? What problems 
does it solve?

> What do you think and suggest?

I think it's better to understand issues and make informed 
choices rather than following the rules of others.

I suggest you consider whether global is bad in this case 
and what other solutions might be used instead. Then make 
an informed choice. If, having researched the subject you 
don't understand why global is (sometimes) bad ask for 
more info here.

HTH (a little),

Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list