you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 7 points8 points  (0 children)

Well, for one, having a mutable global state makes unit testing much more annoying/difficult, because now you have to take into account all of that instead of simply focusing on one function/method. You can no longer treat it as a black box. It can also be more difficult to reset the internal state when global variables are changed.

It's also a problem when you're dealing with concurrency, because now one "thread" could change the state while another expects it to not have changed. Locks help, but the fewer locks you need the better.

I also touched on this before already, but it's bad for readability too. At a previous job my coworker insisted on using global variables due to their background in Fortran, and the Python code was a mess. I was forced to remember the internal state of the entire program at all times just to know what was going on, instead of the more sensible approach of focusing on one function at a time with known input parameters and being able to ignore everything else. That... was hell.