Prototype based vs. class based inheritance
21–26 of 26 posts
Re: Prototype based vs. class based inheritance
#22Re: Prototype based vs. class based inheritance
#23See: 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…
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 things. But that's not really a property of prototype languages…
The way I write object-centric code in Lua feels very different from in Python, even though both languages are dynamically typed (and otherwise fairly similar). It probably has to do with conventions / what's "Pythonic". I haven't used Ruby enough to comment.
Re: Prototype based vs. class based inheritance
#24Re: Prototype based vs. class based inheritance
#25Earlier quoted context omitted.
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 things. But that's not really a property of prototype languages…
Dynamic and duck typing does help quite a bit there, but I think the default stance of prototypes rather than classes also makes a difference. The way I write object-centric code in Lua feels very different from in Python, even though both languages are dynamically typed (and otherwise fairly similar). It probably has to do with conventions / what's "Pythonic". I haven't used Ruby enough to comment.
Re: Prototype based vs. class based inheritance
#26Earlier quoted context omitted.
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 things. But that's not really a property of prototype languages…
Dynamic and duck typing does help quite a bit there, but I think the default stance of prototypes rather than classes also makes a difference. The way I write object-centric code in Lua feels very different from in Python, even though both languages are dynamically typed (and otherwise fairly similar). It probably has to do with conventions / what's "Pythonic". I haven't used Ruby enough to comment.
function MySubclass() { }
MySubclass.prototype = new MyNativeClass();
So far everything works as you would expect. Now I'm going to instantiate and initialise MySubclass:
anObject = new MySubclass();
Again, so far ok. Now I'm going to call the initialiser on the object, which creates the native object and binds it to the javascript object
anObject.init()
Boom! Doesn't work, because Javascript objects (at least in JavascriptCore) can't be bound to a native object - a call to JSObjectSetPrivate() fails.
Instead, I do inheritence this way:
function MySubclass() { var that = new MyNativeClass();
var super_init = that.init;
that.init = function()
{
}
return that;
}It works, but I'm no longer using the prototype nature of the language. I admit that this might be due to a flaw in the implementation (not allowing the private data to be set on objects with a Javascript constructor), but it certainly hasn't given my warm fuzzy feelings about protoyping...