Zero-G Programming

There's a pattern in the design of libraries which I've come to call “zero-g design”. A zero-g library is a library which only communicates with the wider system via interfaces provided by the consumer of the library. Default implementations may be provided which interface with the OS, but these can be overridden. Additionally, globals are not used.

Common considerations which are made the subject of such interfaces are memory allocators and filesystem access. SQLite and Lua would be examples of zero-g libraries, and this is one of the factors behind their extreme embeddability.

I call these zero-g libraries because they have no ground, no reference point; they don't point to a particular memory allocator or set of system calls and define themselves relatively to those points of reference.

Making a library zero-g isn't necessarily always desirable. It necessarily requires the addition of abstraction layers and indirection, and is likely to require more context to be passed around, even to do fundamental things like allocate memory. On the other hand, it can make a library much more versatile, embeddable and portable than it otherwise would be. The zero-g nature of SQLite is a key aspect of its widespread use.