Prototype based vs. class based inheritance
stackoverflow.com
Prototype based vs. class based inheritance
1–10 of 26 posts
Re: Prototype based vs. class based inheritance
#2In my experience, prototype-based OOP is less prone to the typical OOP over-analysis - if you just need one object that does something, you just assemble it, that's it, problem solved. Since the default stance isn't designing a generic class for all possible subtypes that exhibit related behavior and blah blah blah, there's less push toward overthinking things.
Prototype-based OOP is also well-suited to runtime modification, since the underlying implementation is usually simpler, but that's a distant second to the above benefit. And while prototypes are sometimes assumed to be less efficient than classes, look at the research from Self* - While some popular languages have poor implementations, it's not inherently less efficient.
Also, I suspect prototypes integrate more smoothly with non-OOP code than classes, based on experience with Lua (which isn't strictly OOP, but typically uses prototypes). To some extent, this blurs with dynamic typing, though - there's only one statically typed + prototype-based OOP language I know of, Günther Blaschek's Omega (described in _Object-Oriented Programming With Prototypes_).
* http://selflanguage.org/documentation/published/index.html Some of the people involved later worked on the "JVM". Perhaps you've heard of it?
Re: Prototype based vs. class based inheritance
#3Re: Prototype based vs. class based inheritance
#4Given a sufficiently flexible and late-bound class system (like Smalltalk's), the differences between prototypes and classes can blur.
But in general I would say that it is easier to build classes on top of prototype systems than vice versa, which is one argument for prototypes.
All prototype implementations aren't the same, though, any more than Smalltalk and C++ both have the same class systems! Javascript and Self are quite different in some ways, especially when it comes to delegation (ie inheritance) and iolanguage and research such as Kevo are different again.
Despite the first answer to the linked question, I don't think that either class based or prototype based languages are easier to write a VM for.
What attracts me most is that prototype systems are conceptually simpler in an Occam's Razor sort of way. Instead of needing two concepts: classes and instances, we only need one: objects.
Re: Prototype based vs. class based inheritance
#5Some thoughts: Given a sufficiently flexible and late-bound class system (like Smalltalk's), the differences between prototypes and classes can blur. But in general I would say that it is easier to build classes on top of prototype systems than vice versa, which is one argument for prototypes. All prototype implementations aren't the same, though, any more than Smalltalk and C++ both have the same class systems! Java…
That's true, but I find you end up having to make the difference. Yes, prototype inheritance is conceptually simpler but in practice it's more complex. In JavaScript, for example, OO code tends to be harder to follow and includes more boilerplate code. You have to make up for the simplicity of the platform in order to get your work done. In more traditional OO languages, inheritance might be more limited but it's also more straight forward and easier to implement, calling parent class methods is build in, and the "this" reference works consistently.
Re: Prototype based vs. class based inheritance
#6Some thoughts: Given a sufficiently flexible and late-bound class system (like Smalltalk's), the differences between prototypes and classes can blur. But in general I would say that it is easier to build classes on top of prototype systems than vice versa, which is one argument for prototypes. All prototype implementations aren't the same, though, any more than Smalltalk and C++ both have the same class systems! Java…
> What attracts me most is that prototype systems are conceptually simpler in an Occam's Razor sort of way. That's true, but I find you end up having to make the difference. Yes, prototype inheritance is conceptually simpler but in practice it's more complex. In JavaScript, for example, OO code tends to be harder to follow and includes more boilerplate code. You have to make up for the simplicity of the platform in o…
Re: Prototype based vs. class based inheritance
#7Some thoughts: Given a sufficiently flexible and late-bound class system (like Smalltalk's), the differences between prototypes and classes can blur. But in general I would say that it is easier to build classes on top of prototype systems than vice versa, which is one argument for prototypes. All prototype implementations aren't the same, though, any more than Smalltalk and C++ both have the same class systems! Java…
> What attracts me most is that prototype systems are conceptually simpler in an Occam's Razor sort of way. That's true, but I find you end up having to make the difference. Yes, prototype inheritance is conceptually simpler but in practice it's more complex. In JavaScript, for example, OO code tends to be harder to follow and includes more boilerplate code. You have to make up for the simplicity of the platform in o…
Re: Prototype based vs. class based inheritance
#8Earlier quoted context omitted.
> What attracts me most is that prototype systems are conceptually simpler in an Occam's Razor sort of way. That's true, but I find you end up having to make the difference. Yes, prototype inheritance is conceptually simpler but in practice it's more complex. In JavaScript, for example, OO code tends to be harder to follow and includes more boilerplate code. You have to make up for the simplicity of the platform in o…
JavaScript has the worst form of prototype inheritance I've ever seen. All the boilerplate code is not the fault of prototypes, but of JS. Also JS prototypes are insanely limited. You can't have multiple delegates and you can't change delegates at runtime. JavaScript's inheritance actually smells like some broken state between class based inheritance and prototypes. It has none of the advantages of either and combine…
Re: Prototype based vs. class based inheritance
#9Earlier quoted context omitted.
JavaScript has the worst form of prototype inheritance I've ever seen. All the boilerplate code is not the fault of prototypes, but of JS. Also JS prototypes are insanely limited. You can't have multiple delegates and you can't change delegates at runtime. JavaScript's inheritance actually smells like some broken state between class based inheritance and prototypes. It has none of the advantages of either and combine…
I've studied other prototype languages (Io for example), but JavaScript is the only one that I use on a regular basis or in a professional capacity. I imagine for the vast majority of developers, JavaScript is their only introduction to prototype inheritance.
Re: Prototype based vs. class based inheritance
#10See: http://www.c2.com/cgi/wiki?ClassesPrototypesComparison In my experience, prototype-based OOP is less prone to the typical OOP over-analysis - if you just need one object that does something, you just assemble it, that's it, problem solved . Since the default stance isn't designing a generic class for all possible subtypes that exhibit related behavior and blah blah blah, there's less push toward overthinking thi…