JavaScript Isn't Scheme (2013)
Whenever anyone compares JavaScript with Self, I cringe. The name of the seminal Self paper was &quot;SELF: The Power of Simplicity&quot; [1]. JavaScript totally missed the boat on simplicity (the entire POINT of Self), and also totally missed a couple of important features that make Self Self [2]:<p>1) &quot;prioritized multiple inheritance&quot;: Inherit from multiple parent objects: you can inherit through any number of parent slots in a Self object, not just one __proto__ or super or whatever, like JavaScript. There are well defined rules that determine the priority of parents.<p>2) &quot;dynamic inheritance&quot;: Dynamically change which parents you inherit from at runtime. In Self, changing who you inherit from at runtime is a useful programming technique, and the VM implements it efficiently (which is why Self is so interesting and has been so influential). But JavaScript sets the prototype when you &quot;new&quot; an object, and it stays that way.<p>Self is simple because there&#x27;s nothing but objects, all the way down. Everything is the same kind of object. Nothing is special.<p>JavaScript does this weird arbitrary thing by using functions as constructors, and also as prototypes, for no particular reason. Those special constructor functions should never be called normally, they should always be called indirectly with &quot;new&quot;. And it means you can only have one constructor. So why the hell are they functions, if you shouldn&#x27;t ever call them? It&#x27;s just another way to fuck up, due to pointless and arbitrary complexity.<p>Being that weird way doesn&#x27;t make JavaScript any more powerful or expressive or efficient, just more complicated, harder to understand, and easier to make subtle inscrutable mistakes.<p>JavaScript punted on the important parts of Self at least as much as it punted on the important parts of Scheme (like call&#x2F;cc).<p>However at least there&#x27;s a perfectly reasonable excuse for not supporting call&#x2F;cc if you have to efficiently interoperate with C code, native libraries and a garbage collector, and the entire system isn&#x27;t written in pure Scheme.<p>But there was no legitimate excuse for screwing up the great things about Self that, if done correctly, would have made JavaScript simpler and cleaner and more beautiful.<p>[1] Self: The Power of Simplicity:
<a href="http:&#x2F;&#x2F;www.selflanguage.org&#x2F;_static&#x2F;published&#x2F;self-power.pdf" rel="nofollow">http:&#x2F;&#x2F;www.selflanguage.org&#x2F;_static&#x2F;published&#x2F;self-power.pdf</a><p>&gt;Occam’s razor. Throughout the design, we have aimed for conceptual economy:<p>&gt;• As described above, SELF’s design omits classes and variables. Any object can
perform the role of an instance or serve as a repository for shared information.<p>&gt;• There is no distinction between accessing a variable and sending a message.<p>&gt;• As in Smalltalk, the language kernel has no control structures. Instead, closures
and polymorphism support arbitrary control structures within the language.<p>&gt;• Unlike Smalltalk, SELF objects and procedures are woven from the same yarn
by representing procedures as prototypes of activation records. This technique
allows activation records to be created in the same way as other objects, by
cloning prototypes. In addition to sharing the same model of creation,
procedures also store their variables and maintain their environment
information the same way as ordinary objects, as described in Section 4.<p>[2] Parents are Shared Parts: Inheritance and Encapsulation in Self:
<a href="http:&#x2F;&#x2F;bibliography.selflanguage.org&#x2F;_static&#x2F;parents-shared-parts.pdf" rel="nofollow">http:&#x2F;&#x2F;bibliography.selflanguage.org&#x2F;_static&#x2F;parents-shared-...</a><p>&gt;This paper describes the inheritance and encapsulation mechanisms we designed
and implemented in one prototype-based language, SELF. Our design
is based on the philosophy that an object’s parents should be treated as shared parts
of the object, and that inheritance should be a simple, declarative way to maximize
the possibilities for sharing. This paper describes two heretofore unpublished innovations:
a prioritized multiple inheritance scheme that unifies unordered and
ordered multiple inheritance, and an object encapsulation model that provides
many of the benefits of class-based encapsulation in a language without classes. In
addition, our inheritance system supports directed and undirected resends to
forward messages to an object’s ancestors, a unique sender path tiebreaker rule
that resolves many ambiguities between unrelated unordered parents, and dynamic
inheritance, which allows an object to change its parents at run-time to effect
significant behavioral changes due to changes in its state.