Python handles globals badly.

tdev at freenet.de tdev at freenet.de
Thu Sep 3 21:05:18 CEST 2015


Now I want reflecting the latest answers:


I have the position of a high-level view 
(cause of lack of Python knowledge internals and compiler stuff,
 but also cause I think a language should be as far as possible 
 user-friendly without knowing too much internals, and yes
 clearly cause of knowing OO-languages where I do not need 
 such code-contamination)
 
So, my high-level understanding of the "global"-keyword so far is:
Give write access to a global var if this is set to this var
inside a current code block.
And this specific syntax construction is probably defined not cause it
is really needed but cause it is assumed to help the developer
avoiding mistakes, which I think is too much over-regulation.


But from the answers given I maybe have to rethink about the
global keyword. It seems to be an absolute need from low-level point of view
- meaning the designer had no other choice as to invent the keyword "global":

Two main reasons for the need of keyword "global" have been posted:

  Compiler -
    Python compiler or compiler at all cannot hide this from the developer?
    (It seems really a scripting problem. PHP has it, LUA has it vice versa,  
     ...)

    Although I cannot really believe it, that technical reasons lead to this 
    design.

    E.g recognizing if it is local or global:

    If this would be under the developer responsibility than this
    is simply achieved by giving well-written var names.

    And a compiler can surely recognize if a defined var xxx outside
    is not a var yyy inside a function.

    Or does anyone really name a global var xxx and a function var xxx?
    I am sure no one at all will do it. I dont want read such a code.



 Function calls (?) -
   I have to admit I did not really get the problematic from 
   the sample provided by Chris Angelico.

   What I can see or mean to see is: 
       it has nothing to do with global-keyword from the high level point of 
       view: give write access, probably to the vars word and otherword.

       And yes, I see the vars independant. 
       And cause you set no "global" they are simple local vars 
       (readable+writeable) 

       This is more about let me assume function call stack and 
       closures things(?) which I think is handled automatically.

   But as said - here I cannot really respond.
   This have to be answered from more experienced users.
   

   
     
My conclusion:
--------------

My intention was to bring this into discussion and see what comes out and
see what are the reasons for this keyword. 
I am not the user who can open the PEP, but maybe the community out decides to do so.

But if this two problems really exists from low-level point of view, then ok, there is no other way than to use this keyword "global".  I have not the experience to answer that. I can accept low-level problems if so.

But then I ask you from high-level point of view 
(if my high level view is correct at all):
Would you remove this keyword if it would be technically possible
or is good for you from high level point of view to have a keyword "global"?

My answer is clear: remove it.
[The same e.g. with switch statement: add it]


Then this is my question now!


Thanks.


More information about the Python-list mailing list