Book Reviews

The Art of the Metaobject Protocol by Gregor Kiczales, Jim des Rivieres and Daniel G. Bobrow

ISBN: 0262610744
Publisher: The MIT PRess
Pages: 345

The basic idea of a metaobject protocol is to implement an object system using its own constructs as building blocks. The fundamental constructs available to application programmers, such as classes, generic functions and methods, are themselves instances of (meta)classes. While the resulting design is remarkably consistent and clean, the big win is that a metaobject provides an extremely powerful extension mechanism. The metaobject protocol behaves like an interface towards the language itself, available for the programmer to incrementally customize. Just as we can specialize and extend the behavior of the classes we define in our own applications, we can now extend the language itself using the very same mechanisms. It's a design resulting from the direct conclusion that no language will be universally appropriate for all problems. Instead of fighting the language, the programmer adapts and evolves it to the problem at hand. The Art of the Metaobject Protocol (AMOP) is a wonderful book to learn about these topics.

A metaobject protocol gives application programmers an interesting context. With a metaobject protocol the available design space isn't fixed. Rather the possible design space extends to a larger region. This region is defined by the extension points in the metaobject protocol. To give an example, say we want to change some aspect of object allocation. Or perhaps we want to change the dispatch rules for a set of types. The practical purpose could be to balance the classical trade-off between speed and memory or, more radically, provide a completely different storage mechanism for our objects (e.g. in a distributed key value store). With a metaobject protocol, such fundamental changes to the language are only a few specializations away. The beauty is that we implement it using the very same mechanisms we'd use for traditional object-oriented programming with CLOS. As such, AMOP presents an approach to language design that is radically different from what we've come to know in popular object-oriented languages of today.

Designing an object system based on a metaobject protocol is an old and mature idea by now. Yet the idea is conceptually challenging. For once, how do you start? The consequence of a metacircular object protocol is that initial metaobjects will have to be instances of themselves. Clearly, we can't have full-featured CLOS objects all the way down; at some point they need to rest firmly on a turtle. I was delighted to see that AMOP covers these decisions and bootstrapping strategies as well. Basically, the typical bootstrapping approach is to hand-code the initial metaobjects. This strategy rests on the assumption that we only need a minimum set of fundamental metaobjects with known slot-values up-front. The challenge, as AMOP puts it, is to create these initial metaobjects with as little effort as possible.

The book serves two purposes. First, it's mandatory reading if you want to dig deep into CLOS and unleash the power of its metaobject protocol. AMOP is the definitive guide here. The only remark I have is that while AMOP provides a complete discussion on the implementation of the protocol itself, it's quite weak on possible applications and use cases. In practice this is less of a problem. Today there are several open-source libraries that extend CLOS through its metaobject protocol. For example, the elegant Elephant library uses the metaobject protocol to provide simple persistent objects. I'd recommend the Elephant source code as a useful reading companion to this book.

The second role of AMOP has a wider audience. In Fred Brooks's book The Design of Design he makes the case for exemplars. The idea is that designs, even novel ones, derive from earlier work in similar fields and technologies. By studying our precedents we can learn from their work. Brooks views exemplars as a safe model and launchpad for new designs. It's in this role as an exemplar of great design that AMOP partly transcends Common Lisp. Since the line between program and language design is blurred in Lisp, the lessons learned in AMOP are applicable to application programmers too. And I have no doubt that language designers could turn to AMOP for both inspiration and practical advice.

AMOP is a rewarding technical book that I highly recommend. As pre-requisites you need a good grasp of both Common Lisp and CLOS. AMOP does provide a brief CLOS introduction, but I don't think it's sufficient to appreciate the advanced concepts in the book. To learn CLOS, I recommend Object-Oriented Programming in Common Lisp by Sonya Keene. And if you're a newcomer to Common Lisp my standard recommendation is Practical Common Lisp by Peter Seibel. These two books will lay a solid foundation. Once you're there, AMOP provides a way to think about object-orientation that is still radically different from the mainstream alternatives of today.

Reviewed March 2014