I just ran across this old question asking what's so evil about global state, and the top-voted, accepted answer asserts that you can't trust any code that works with global variables, because some other code somewhere else might come along and modify its value and then you don't know what the behavior of your code will be because the data is different!  But when I look at that, I can't help but think that that's a really weak explanation, because how is that any different from working with data stored in a database?When your program is working with data from a database, you don't care if other code in your system is changing it, or even if an entirely different program is changing it, for that matter.  You don't care what the data is; that's the entire point.  All that matters is that your code deals correctly with the data that it encounters.  (Obviously I'm glossing over the often-thorny issue of caching here, but let's ignore that for the moment.)But if the data you're working with is coming from an external source that your code has no control over, such as a database (or user input, or a network socket, or a file, etc...) and there's nothing wrong with that, then how is global data within the code itself--which your program has a much greater degree of control over--somehow a bad thing when it's obviously far less bad than perfectly normal stuff that no one sees as a problem?
How are globals any different from a database?
state;globals