The absolute worst type of global mutable state I've had to deal with personally follows this antipattern:
oldEnvironment = getGlobalEnvironment()
SwitchToGlobalEnvironment("Foo")
- Do things that rely on the "foo" globals
SwitchToGlobalEnvironment(oldEnvironment)
Or, worse, functions like this:
// NOTE: DO_STUFF assumes "FOO environment". Set FOO ENVIRONMENT before you call it.
def doStuff() {
- Do stuff that relies on foo environment
}
or:
// NOTE: depends on the value of global FooBar. Adjust FooBar to make DoStuff2 behave how you want
def doStuff2() { ... }
I suppose you never worked with old ASP or PHP apps where the first thing every page did was throw every form field value into the global Session object?