Methods vs. Functions (Re: [Python-Dev] A house upon the sand)

Guido van Rossum guido@python.org
Mon, 27 Nov 2000 19:07:38 -0500


> > Mr. Meyers presents some very well-reasoned arguments
> > against the everything-should-be-a-method mentality.
> 
> Note that the motivation for turning to string methods was
> that of migrating from strings to Unicode. Adding Unicode
> support to the strop C module would have caused very complicated
> code -- methods helped by enabling polymorphic code which is
> one of the great advantages of writing software for an interface
> rather than an implementation.

Of course.  Meyers starts by saying that if it needs implementation
details it must be a method.  This is true (if only for efficiency
reasons) for most string methods.

> Note that functions can make very good use of methods and
> thus implement polymorphic functionality -- this is not
> about methods vs. functions it's about methods to enable
> polymorphic functions.

Meyers also says that if it needs to be virtual it needs to be a
method.  Polymorphism is roughly equivalent to virtual in this
context, and this alone justifies the move to methods.

But join() is special: it is polymorphic in two arguments, and making
it a method of the separator argument doesn't help.

--Guido van Rossum (home page: http://www.python.org/~guido/)