[Tutor] Global variables

Kermit Rose kermit at polaris.net
Thu Aug 17 06:17:47 CEST 2006


 
 
From: Alan Gauld 
Date: 08/15/06 03:37:21 
To: Kermit Rose; rabidpoobear at gmail.com 
Cc: tutor at python.org; dyoo at hkn.eecs.berkeley.edu 
Subject: Re: [Tutor] Global variables 
 
. 
 
The names have very little to do with it, the danger of global 
variable 
use is the reliance on side-effects and the tight coupling that you 
introduce between the calling module and the called module. 
Changes to the state of the calling module in an unpredictable 
manner lead to subtle bugs which are extremely hard to see and fix. 
 
*****
 
Huh???
 
What side effects do you have in mind?
 
I certainly did not know any side effects existed.
 
What do you mean by tight coupling?
 
The only change I can see that would lead to a bug would be if I changed the
name of the global variable in
the calling routine and not in the function it called.
 
I would know not to do that.
 
 
 
>>>>>>>>>>>
 
Confusion of names is of very little import, that really isn't the 
issue. 
 
**********
 
Is it that global variables are no implemented correctly?
 
I can't imagine what the issue would be if it isn't confusion of names.
 
>>>>>>>>>>
 
 
 
I'd be very very doubtful that its a bug in Python. 
Python is very well tested and while occasionally bugs do surface, 
the type of bug you are describing is extremely unl;ikely to have 
remained hidden. It is far more likely to be an error in the code 
or in the data. 
 
 
*******
 
I understand your skepiticism.   I would be too in if I were in your
position.
 
I've just sent the documentation to the list,  in my message to Luke.
 
>>>>>
 
 
All of which points to an error in the code not in Python. 
The way Python is written it is virtually never going to result in 
that kind of error dependant on data values. 
 
 
******
 
Which is why it surprised me.
 
>>>>>>>>>>>
 
 
That might happen 
is if the values are very close to zero and a type conversion 
occurs, but otherwise I'm very dubious about a Python bug 
of that type. 
 
 
*****
 
Indeed.  Errors of this type would be found by chance, like I found it.
 
It would be impractical to search for this type of error.
 
It is not a type conversion.
 
The error is occuring between the return statement in the called function
and the picking up of that value
in the calling function.
 
 
 
 
 
 
 
 



More information about the Tutor mailing list