Steven D'Aprano napisaƂ(a):

>> 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 (eg functions, methods and lambdas are differen beeing in
>> Python concept).
> 
> Please explain why you think that functions are more complicated in 
> Python because of the class model.

Sorry for a late reply (I was out of the office).


1. You have different syntax for named and unnamed (lambdas) functions. 
Functions and methods are different things in Python even if they have same 
syntax. But all these are still a pieces of code that you use repeatedly to 
make 
some task.

2. Static function doesn't need to reference "self", and Python forces 
programmer to put "self" explicitly. Then you have to do some "tricks" on 
function to become static. Python is said "nothing is really private", but 
interpreter does some "tricks" to make __id hidden for a class.


Some opinions:

1. In early days you could do OOP in C -- you just used additional parameter in 
a function. Then C++ appeared to make life easier: "when you write 
mystring.toupper(), then toupper function gets hidden argument called "this"". 
Programs are written in a high level object oriented languages now. In these 
languages you still use the same syntax mystring.toupper(), but now you don't 
pass object to a function (as in C), but you act on that object. So in the body 
of toupper() you can REFERENCE object "mystring". So why do I have to put that 
"strange" argument "self"?

This is not only my opinion 
(http://apache.ece.arizona.edu/~edatools/Python/Prototypes.htm). Without "self" 
you would use same syntax for ordinary functions, methods, and lambdas.


2. Something is private because you can't reference that from outside the 
scope. 
The wrong way is to make object properties private by declaring them private or 
to do hidden actions (__id). For example all local variables in function are 
private, because you can't access them from outside that function. Why desn't 
this work for objects?

Again this is not only my opinion -- 
http://www.crockford.com/javascript/private.html.


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to