Prototypal Inheritance (2008)
crockford.com
crockford.com
I've been having a lot of conversations recently with people about LLMs and how a prototypal inheritance-like approach to working with them seems to be surprisingly effective. Especially for writing code.
Also, this quote jumped out at me: "Insights from the dynamic world can have application in the static."
If you provide a "prototype" to a model, you can operate on that prototype and create new instances or variations of it. This is useful for working with code by defining an abstraction or a class, and then having the LLM work with and modify it, generating new code that fits or inherits conceptually from that original prototype.
I do like writing Javascript that way, though:
function Thing(otherThing) {
const self = otherThing || {};
self.method1 = function () { /* ... */ };
// self. [...]
return self;
}
function main() {
// no `new`, no `this`
const thing = Thing();
// ...
}[1]: https://www.lua.org/pil/13.1.html
> And it's still maybe for its field of application the best language in the world for doing that kind of stuff but that's not good enough. We should be moving on to the next generation of languages. It used to be that we'd get new computer languages about every generation. That started with Fortran and then C and C++ and Java and JavaScript and so on and then it kind of stopped. There are still people developing languages but nobody cares. One person can make a programming language, a really good one, but you can't get adoption for it.
This isn't Crockford becoming converted to the anti-JS crowd and hopping back to C, it's Crockford arguing that JavaScript shouldn't be the final iteration of programming languages. Presumably he believes that about C as well.
It looks like he's working on writing a new language, Misty, intended to (maybe) replace JavaScript:
Because prototype chains feel a lot like MRO but without the facilities to support multiple inheritance (which can be good or bad depending on the programmer).
This so called inheritance is best understood as linked-lists which "help track the method that acts upon this object". So this' not the OOP in Python (where you have C3 inheritance), nor the one in C++ where you have DFS inheritance, and does not even "support" multiple inheritance (https://en.wikipedia.org/wiki/Multiple_inheritance). I want to say is not inheritance, but... well it was billed as one, so you can think of it as one. But is in fact a peculiar way of doing method resolution.
Is the difference that one draws a line between classes and instances? So like in JS an object is a "subclass" of its parent in addition to being an instance of it because the line between them doesn't exist.
If in JS every object had .prototypes plural it seems like it could work with C3 linearization in exactly the same way.
Like they say, there are many benefits of prototype inheritance compared with class inheritance, and I agree with that.
I think that it is not a good idea to affect Object.prototype, and I think it might have been a bad idea even to put anything there at first when they invented JavaScript. (For this reason, sometimes Object.create(null) is used, which creates an object with no prototype.)
What they describe there was the inspiration for the existence of Object.create. This is a historical post from Crockford, the godfather of JS.