Prototype OO
Bruno Desthuilliers
bruno.42.desthuilliers at wtf.websiteburo.oops.com
Wed Mar 26 08:18:07 EDT 2008
sam a écrit :
> Bruno Desthuilliers napisał(a):
>
>>> In dynamically typed language when you create object A that is
>>> inherited from another object B, than object A knows that B is his
>>> predecessor. So
>>> when you reference A.prop, then prop is looked in A first, then in B,
>>> then in predecessors of B, and so on.
>>
>> What you're describing here is the inheritance mechanism of Python.
>> And could apply just as well to javascript prototype mechanism. A
>> javascript object has a reference to it's prototype object - that you
>> can customize, rebind etc -, a Python object has a reference to it's
>> class object - that you can customise, rebind etc...
>
> I can see that Python and Javascript inheritance model is almost the
> same. Both languages are dynamically typed. And it seems that using
> "classes" in Python makes some things more complicated then it is
> necessary
I have to disagree here.
> (eg functions, methods and lambdas are differen beeing in
> Python concept).
The lambda statement creates an ordinary function object, so no
difference here - and it has nothing to do with classes vs prototypes.
wrt/ functions and methods, what you declare with a def statement within
a class statement is actually a plain function (and FWIW, you can add
dynamically add methods to classes or instances). Python 'methods' are
only thin callable wrappers around the function/class/instance set,
wrappers that are dynamically generated by the function object itself
when it's looked up on a class or instance, thanks to the descriptor
protocol.
>
>
>> Don't be fooled by the term "class" itself - it's meaning is totally
>> different in a language like Python.
>
> Probably I'm not alone. Many people who think dymanic types are Rhight
> Thing in programming will also prefer prototype-based programming to
> class-based.
Chapter and verse, please ?
Ok, I repeat (please read more carefully):
"""
Don't be fooled by the term "class" itself - it's meaning is totally
different in a language like Python.
"""
>
>> suspect you don't have a serious knowledge of Python's object model.
>
> Yes -- I'm new to Python.
So may I suggest you actually *learn* how Python's object model works ?
More information about the Python-list
mailing list