Summer reading list

Michele Simionato mis6 at
Sat Aug 16 14:30:25 CEST 2003

jjl at (John J. Lee) wrote in message news:<87ekzmsi5c.fsf at>...
> mis6 at (Michele Simionato) writes:
> > To reuse classes is good, but typically only works when you know
> > about the class you want to inherit *before* you start coding your
> > own class; on the other hand, it is quite easy to add functions
> > or methods to your class even *after* you wrote it.
> [...]
> But I don't think that makes any sense.  As I'm certain you know,
> there would be nothing to stop you using a class in exactly the same
> way you used the function, because reuse != inheritance.  Functions
> can be implemented in terms of classes, and classes can be implemented
> in terms of functions.

Let me see if I understand what you mean. You are saying "I could invoke
an instance method just as I invoke a function, without using inheritance,
and reuse the method in another class". True, but this is clumsy: the point 
of using a class is making use of inheritance for code reuse,  otherwise I 
could just use a function, isn't it? Besides, typically an instance
method is doing something to the 'self' argument and may have unwanted
side effects on the object; a function is safer in this respect.
In my experience, it takes a certain effort to code a reusable class; 
it takes a much lesser effort to code a reusable function.

> The only reason it's good that Python library uses functions sometimes
> instead of classes is as you say: KISS.  If it only needs a function,
> use a function.
> John



More information about the Python-list mailing list