On 30 Jul 2009, at 14:03 , 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."
?
Depending on the way things are implemented, it can be very similar
(see CLOS' generic functions, which have the same look as functions
but dispatch based on parameter types).
In Python, the difference would be that functions don't automatically
dispatch (you have a function for everybody, and any dispatch you
perform based on argument types or other qualifiers has to be done
manually) whereas methods do dispatch on the first [implied] argument
(you execute a precise method corresponding to the object it's being
called on).
So fun(obj, *arguments) will call the same `fun` whether `obj` is an
int, a string or an HTTPFactory whereas obj.met(*arguments) will call
a different `met` each time (they all have the same "unqualified" name
[and signature if it's part of a protocol], but might very well be
implemented completely differently). Therefore -- in python -- the
effect isn't anywhere "just about the same".
--
http://mail.python.org/mailman/listinfo/python-list