Python handles globals badly.

Skybuck Flying skybuck2000 at hotmail.com
Tue Dec 2 23:17:04 EST 2014


Meanwhile...

I modified my code, and added these globals in front of it.

It didn't take too long to do.

But it did add something like 300 "unnecessary" lines of code, which is what 
kinda annoys me.

I'd like to keep my code compact.

Anyway I double checked to make sure other routines had global for other 
variables as well.

Perhaps I made some programming mistakes which went unnoticed because of 
smart code handling optimizations and such.

But because the global was omitted perhaps those optimizations never kicked 
in.

I am not completely sure, but so far my bot seems to run real fast.

Personally I do not like the way "global" works in python... it sucks quite 
bad, because it's confusing and inconsistent as hell and it doesn't do 
anything usefull example:

a = 1

def Test()
    if a == 1:
        print "hello"
    return

"a" can still be accessed by Test, so this makes it highly confusing ?!

Should global be added to a or not ?!

This creates doubts among the programmers.

Was "a" perhaps maybe initialized or not ?

What is it's contents ?

The lack of a debugger in Sikuli makes this problem much worse.

Only way to know for sure would be to print debug logs of variables which 
would get a bit excessive to do always, but I guess in case of doubt perhaps 
it could be done temporarely, however this additional "paranoid" checking 
does waste some programmer time.

Therefore enough reasons for me not to like this... it's weird/akward.

I hope python one day gets rid of it;

1. To stop the confusion.
2. To stop the doubt.
3. To stop the wasted lines.
4. To program with more confidence.
5. To stop to have to inspect what's going on if one wants to know for sure.
6. To stop any weird programming mistakes because a global declaration was 
not used somewhere in a function, it's probably easier to miss, cause in the 
programmers mind he's thinking: "it's global".

Now it's just some 
half-ass-fucked-up-not-really-global-variable-unless-you-specify-it-local-to-be-global-holy-shit-batman-feel-the-brain-pain 
?!

Bye,
  Skybuck. 




More information about the Python-list mailing list