First-Class Namespaces in Programming Languages

A graphical depiction of a very simple xml doc...

Image via Wikipedia

Over the last few years, I've written plenty of programs--in various languages--that used a HTTP library to fetch an XML document pointed at by a URL and then used XPath to grab parts and pieces of that XML document. The problem with this is that I'm using two different namespaces (the URI and the XML) neither of which is directly supported by my programming language.

Programs that use relational databases suffer similarly: a datastore with a namespace that is extralingual. One of the great selling points of JSON is that it reduces the cognitive load of programmers by getting rid of at least one namespace by simply reading the data into the program's namespace directly.

Historically, programmers dealt in local, in-memory data structures that they usually built themselves programmatically. Modern programmers face the challenge of multiple namespaces at every turn and yet our programming languages haven't grown up to help us meet those challenges. They provide nice linguistic abstractions for dealing with local data, but force the programmer to make all the mental leaps necessary to translate between the local store and any remote ones.

This week Drummond Reed came to visit for a day and as we talked, I realized that you could resolve this situation by giving the programming language a namespace vocabulary rich enough to handle most remote and local situations. Further, with what we've learned about namespace resolution over the last decades, we can resolve namespace references in ways that programmers wouldn't have to worry about whether data was local or remote. Programmers could just use a reference and anywhere a variable would do and let the underling system worry about the details.

Of course, since I was talking to Drummond, XRI and XDI were the primary focal points of our discussion. XRI is a well-thought-out system for creating URL-like namespace references. XDI is a way to resolve those references into data. Using XRIs you can create abstract references to data regardless of whether it's local, comes from a URL/XML combo, lives in a session hash, or even resides in an information card on the user's machine.

I believe that incorporating XRI references into a programming language as first-class objects would offer a powerful abstraction on data. I'm anxious to give it a shot. The trick, of course, is to continue to make easy things easy to do without complicating every variable reference while at the same time allowing programmers to leverage the power of other namespaces when needed.

I'm sure there's a programming language out there--maybe even a dozen--that provide support complex namespaces. I'd love to know what they are and how they've worked. In the meantime, this is what I think about when I'm driving.