Python handles globals badly.

tdev at freenet.de tdev at freenet.de
Fri Sep 4 15:11:18 EDT 2015


Now I want reflecting the latest answers:


I think mostly everything is said.
Maybe you skip directly to my conclusion on the end.


--

Nevertheless I want grasp some points out
where I think I could give a respective answer:

  
"You are shifting declaration from one to another place"

I would not say so: 
maybe it is a special prefix, but that you write once 
and not in every function (with additonal at least one "ugly" line of code). 
See no shifting here.
And I think it cannot be duplicated elswhere cause you are in
your single module's namespace. 
See no conflicts here.


"You would create than all in one scope"
(or "You would create namespace vulnerabilities")

I would not say so:  
An enclosed code block has still its own scope.
But if there is a global module var (e.g. recognized by a distinct name)
inside this block than this var is from scope global.
See no conflicts here.


"Learn better Python"
I am sure I am not alone (although the thread seems to isolate my opinion)
And you maybe have recognized I have accepted that there is a need for "global".
But admit I have to chew hard. 
See my conclusion. 


"Java have it ugly too"
I would not say so:  

The examples providing with one var and one function does
not reflecting real scenarios.

Guess mostly classes have about 10 members and 10 functions.
Each member about 10 chars long with 10 lines of code per function.

seeing the global var inline is more readable than
looking on the top of the function if the var is global or not
+ the addtional lines of code onyl cause making it global.

I dislike @xxxx too (also in Java).

See the contamination in that point still in Python.

--



Conclusion:
-----------

I think we can agree 

- that there are (unfortunately) low-level issues
  that makes the removing of "global" impossible. !?

- and there are also special (dynamic) programming constructs 
  where a keyword "global" makes sense and should be available !?


I think for a scripting language this would be a good solution:
when used then the compiler should definitive look in the global namespace,
otherwise the compiler has some "magic" to distinct global from local
(probably simply by varname and scope of birth) 



And yes it is not that I want change Python mantras.
But Python philospy is so far I know:
"There's a most understandable way to do something and that is how it should be done"

But that says not: Do not change things that makes the life easier for a developer
                   (escpecially who wants to do simple or powerful procedural/functional scripting).


So for me there are 6 things that is somehow "masochistic" in Python
cause with all its powerful features it is remarkable that it is not addable.

So, If I had the power I would include following features
(especially as we talk about scripting and cause why not (?), 
it would not harm anyone who does not want to use it (!)):

all is optional (so hardcore Pythonier would probabyl deny to make use of it):

1. optional keyword "global" (if technical possible)
2. switch statement
3. less restrictive indentation 
   (as if it would really matter forgetting an empty space somewhere
    if something is intended more right than is the context clear for me)
4. universal scope 
5. goto label
6- "include" script statement (extending namespace to another script, like PHP)

    
I think this would make Python even more popular than it is now.
Not to say: I would really love it then.



Last but not least: 
Why does javascript, as sripting language too, need not such things like
a keyword "global". It also very powerful language with dynamic binding, OO, ...

This is my question now.



More information about the Python-list mailing list