Confessions of a Python fanboy

Jean-Michel Pichavant jeanmichel at sequans.com
Thu Jul 30 08:24:39 EDT 2009


superpollo wrote:
> Masklinn wrote:
> ...
>> That's an interesting point, but not relevant at the end of the day:  
>> `foo.length` and `length(foo)` have the same "practicality". On the  
>> other hand Ruby can be praised for the coherence: everything's a  
>> method period end of the story; while Python does have a dichotomy  
>> between methods and functions/generic methods (whether or not that  
>> dichotomy bothers users is another issue).
> ...
> how would you correct a newbie (like me) who says:
>
> "well, the main difference between a function and a method (from the 
> caller's pow) is a syntactic one:
>
> fun(obj, arguments)
>
> as opposed to:
>
> obj.met(arguments)
>
> but the effect is just about the same."
>
> ?
>
> bye

My suggestion

- OO programming:
length(foo) calls the foo instance(or class for some language) length method
length(bar) calls the bar instance length method, it is **not** the same 
than the foo method

- non OO programming:
length(foo) calls the length function with foo as parameter
length(bar) calls the **same** length function with the bar parameter 
(so you better make sure length is handling both foo and bar)

So the difference is definitely **not** a syntactic one, but it is true 
that the syntax obj.method() better illustrates the bind mechanism of 
the OO programming.

JM




More information about the Python-list mailing list