Fun with word mincing: what’s global?
I had a fun discussion with Rob on my last post, which led me to think about global variables and what we mean by “global”. Rob was arguing that a Node module is not strictly speaking global because it isn’t accessible unless you require it. That’s accurate, of course, but I’d still call that global in the sense that any code in the application that calls require will get the exact same object. The trick however is to only export from your modules constructors or factories. This way, the exported object may be global, but only in the same sense that a .NET class is a global object: everybody sees the same System.String, but it doesn’t matter in the least, because the string instances that you create from it are not global unless you make them. It’s still a little easier to shoot yourself in the foot in Node because functions and class constructors are ordinary objects, and the wrong pattern of exposing a singleton as a module is quite easy to write, but I’ll admit that it’s a mistake you’re probably going to make only once. So. On the same page here, I think.
What about mincing that word a little more finely?
What do we mean by “global” in the first place? Well, it’s a really relative notion. Most of the time, we mean something that is going to have the same value across the whole runtime where our code is running. It’s a scope, and it’s the largest scope that we have access to from code. Or is it?
Pretty much any programming platform will give access to the system’s environment variables. Hmm, that’s more global than global: all runtimes in the system will see the same values. Can we go even more global?
Sure we can: are there values that are going to be shared by all systems in the world? Well, yes, DNS is an example. If we want to go really big, we can even consider time as a global variable (even if Einstein made things a little more subtle than that), or physical constants. But even physical constants may not be at the grandest possible scope: if we live in a multiverse, there may be regions where the constants have entirely different values. Are the laws of physics then truly global? We don’t know. We think there may be different, viable (in the sense that they are consistent) universes with radically different laws.
The only truly global things I can think about would be God (if you think that’s actually a thing) and mathematics. But that’s another can of worms entirely…