Python handles globals badly.

tdev at freenet.de tdev at freenet.de
Thu Sep 3 15:22:29 CEST 2015


Reflecting the answers I want to add following first:


I should have better started a new thread.
But now it is here, I want just clarify something before 
I move on (later) with repsonding.


I think this has lead to some confusing.


There are now two main topics in this thread.


First topic: 
"sharing globals between modules"
Where globals is meant as vars used throughout the app.

This is the topic why Skybuck starts the thread.
And yes I agree globals can be bad design
and it is solved via outsourcing to an extra module and used via imports.

I misinterpreted this topic a little by thinking 
the focus is more about the use of the badly "global" keyword
(in my point of view) and added therefore my post here as


Second topic: 
"Forced to use "global" for write-access inside functions 
is over-regulation and should be removed."

This topic has nothing todo with sharing globals.
It is about in the scope of a single module only.

When I have written globals in this topic 
I have meant and mean vars defined in a module outside 
functions and used inside function blocks.

Sorry if this has lead to confusion, but so long 
I have read docs I would say that these vars are 
often named as globals although I meant module vars.

Reason is that module scope is the highest
scope and often referred as the global scope.
That is also why I dislike the word "global" too.


I talk about this construct:

Sample "Bad":
module A
   _x = 0

   def y():
	global x
	_x=1


and I aim for - it would be nicer to allow for simplicity
writing this without the keyword "global"
and give this small responsibility ("write protection")
back to the developer:

Sample "Good":
module A
   _x = 0

   def y():
	_x=1


why - this I have tried and try to explain in my and your posts 
      in the hope a PEP will arise which frees me and hopefully
      a lot other developers getting forced to use "global"
      (If developers need this "global" - ok, but I and 
	hopefully more want not to be forced with that 
        code-contaminator, especially having a lot more vars)


Said that, I will not respond to comments about sharing globals


More information about the Python-list mailing list