Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can't inherit a class from an instance in python. Classes and instances of classes are distinct (though the semantics aren't equivalent, a class is described as an instance too, but of a metaclass, not of its parent classes). Both can only inherit from classes. Once you instantiate an instance, your inheritance is terminated.

I can derive any object from any other object in Javascript. An object can be treated as a class, a metaclass, or an instance. There is no language difference. That isn't just syntax, that is a deep part of the implementation and semantics.

Both languages are Turing complete, so of course one can build a system that does prototypal inheritance in Python, in fact it is rather simple, given Python's powerful delegation system. Just as you can create classes in Javascript. But there is a difference.

If you disagree, it may be worth you giving a definition of what you think prototypal inheritance is, as distinct from class-based inheritance.

> perhaps you can take your FooClass and run it through a function, permuting it as desired, but then, you would still need to do that at every base-class's definition site

You don't have FooClass in Javascript in the same sense. There is no metaclass in Javascript, because there is no concept of a class. Thus the restriction of the two-level ontology doesn't raise its head.

> follow the prototype chain, follow the MRO

This is the same for any class-based language. There is a delegation chain that goes from instance -> class -> parent class, etc.

So again, what do you think would make something prototypal? Do you think it is a meaningless term? Or just something fashionable to make Javascript sound important?

This isn't bashing Python, you can do plenty of stuff in python. But it does have a different model of object orientation to Javascript. Fortunately Python is flexible enough to subvert that if you need to. But that's not what the terms mean. It isn't the only language that is powerful enough to be able to implement alternate OO models.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: