Wednesday, September 03, 2008

Of Objects, Classes and Metaclasses

"The greatest talents are slowly mastered" (Lao Tzu)

It started with the metaobject protocol, moved on to metaclasses, and culminated in this paradoxical statement from Wikipedia: "[T]he metaclass of Metaclass is an instance of Metaclass."
  • An object is an instance of a class.

  • A class is a singleton instance of a metaclass.

  • A class is also an object.

  • A metaclass is also a class (as well as an object, of course).

  • A metaclass, being a class, is a singleton instance of a metaclass.

  • Metaclasses are instances of the class Metaclass.
Which, I think, leads us to the Wikipedia quote.

Class diagram (Smalltalk-specific, with a few bits omitted for clarity; also, NumberMetaClass isn't named as such):



I started off with the profound quote from the Tao Te Ching, but I'm not really sure what the utility of this stuff is, unless I'm implementing a Smalltalk virtual machine. Well, I can at least sleep peacefully at night, knowing that if ever I run into the Wikipedia quote again, I know that I can figure it out. Sort of.

Staying on the subject of objects (pun unintended), here's a delightfully candid quote from an interview with Alexander Stepanov (emphasis mine):
Question: I have done a search on Lycos for your papers and I only found two titles: the STL manual and a resume of you presentation of STL to the standardization committee.

Answer: Well, I am lazy, but not that lazy. I probably published 20 papers and a book. Many of them are on different STL sites. (Dave Musser's site probably has several.)

Question: Which book?

Answer: The book is "The Ada Generic Library: Linear List Processing Packages", by David R. Musser and Alexander A. Stepanov, Compass Series, Springer-Verlag, 1989. It is not really worth reading.
Trivia: there are 23 occurrences of the word 'class' in this post.