Self is wonderful and beautiful, and that "Power of Simplicity" paper
is excellent reading, a true classic. |
Like with Lua, you can also roll any kind of object system in Self, but it's excellent for making prototype based object systems (and making them run fast, albeit by using lots of memory).
That paper covers some original techniques that can be applied to just-in-time compilers for many other oops like Smalltalk, Java and Lua: aggressive inlineing, polymorphic inline cache, virtual classes (they're prototypes in the programmer's mind, but Self optimizes them to virtual classes behind the scenes) dynamic de-optimization (pessimization :) for debugging, etc. The people and technology behind Self led the way to Sun's "HotSpot" just-in-time compiler.
Another powerful approach to prototype based oop is OpenLaszlo's "instance first development", as described by Oliver Steele (who managed the Dylan project at Apple, and designed OpenLaszlo):
"LZX is a prototype-based language: any attribute that can be attached to a class definition, can be attached to an instance of that class instead. This is handy in UI programming, where there are a number of objects with one-off behaviors. It’s also handy in prototyping and incremental program development, where it creates the possibility for a novel kind of refactoring."
"The equivalence between the two programs above supports a development strategy I call instance-first development. In instance-first development, one implements functionality for a single instance, and then refactors the instance into a class that supports multiple instances."
"In instance-first development, one implements functionality for a single instance, and then refactors the instance into a class that supports multiple instances."
"The syntactic version of the instance substitution principle makes a class look like a function or a macro. Class, function, and macro definitions are all mechanisms for abstracting program structure so that it can be reused."
Roberto Ierusalimschy wrote:
OK, I understand that I can implement class-based OOP in Lua. Can you provide any analysis on when prototypes are better or worse than classes?I think the papers about Self (the first language to propose prototype-based OO) are a good reading (although of course their analysis is somewhat biased). The classic "Self: The Power of Simplicity" is a good start: http://research.sun.com/self/papers/self-power.html -- Roberto