2 ms·
The arguments here all seem to assume that you're writing the code yourself. I think the best argument against rampant global state is when dealing with other p
by jamii 17y ago
The arguments here all seem to assume that you're writing the code yourself. I think the best argument against rampant global state is when dealing with other peoples code.
An example from a couple of months back. I was using an open source library for parsing LaTeX code before it was added to a search index. After getting the alpha version up and running I ran into a subtle bug - malformed input such as "$$ \dot{C}O_2" would break every future parse of any mathematical input. So somewhere in this 20k loc library a global variable is not being reset after parsing. Since this is an imperative language there is no way to figure out which part of the call chain is calling which global variables so I potentially have to read every line of code of find it.
After two days I managed to track it down by writing a script that reads the source code to identify every static global variable in the code and tracks their values between calls. This is not the ideal way to find bugs.