← All Posts · ← Newer · Older →
Origin of metaclasses in Python
October 24, 2013 — originally posted on
The History of Python
There was some speculation on python-ideas today on whether Python's metaclass design came from Ruby. It did not. And as long as we are speculating about the origins of language features, I feel the need to set the record straight.
I
was not inspired by Ruby at that point (or ever :-). Ruby was in fact
inspired by Python. Mats once told me that his inspiration was 20%
Python, 80% Perl, and that Larry Wall is his hero.
New-style classes were just the second or third iteration of the idea.
But even Python's original design (in 1990, published in
1991) had the notion that 'type' was itself an object. The type pointer
in any object has always been a pointer to a special object, whose
"data" was a bunch of C function pointers implementing the behavior of
other objects, similar to a C++ vtable. The type of a type was always a
special type object, which you could call a meta-type, to be recognized
because it was its own type.
I was only vaguely aware of Smalltalk at the time; I
remember being surprised by its use of metaclasses (which is quite different from that in Python or Ruby!) when I read about
them much later. Smalltalk's bytecode was a bigger influence of Python's
bytecode though. I'd read about it in a book by Adele Goldberg and
others, I believe "Smalltalk-80: The Language and its Implementation" (
http://www.amazon.com/Smalltalk-80-The-Language-its-Implementation/dp/0201113716).
Comments (1)
Guido van Rossum — October 24, 2013
Also note that that 1998 essay contains a fully-functional Enum implementation that has many of the same features as PEP 435. (Via Christian Heimes.)
← All Posts · ← Newer · Older →