merits of Lisp vs Python

Cliff Wells cliff at develix.com
Mon Dec 11 15:27:41 EST 2006


On Sat, 2006-12-09 at 00:26 -0800, hankhero wrote:

> The Common-Lisp object systems has all and more OO-features, some which
> you never probably have thought of before. Here's one:
> Inheritance lets you specialise a method so a rectangle and a circle
> can have a different Draw method. If you wouldn't have OO you would
> need a function with if statements to dispatch on thing, if
> thing=rectange then drawRectangle if thing=circle then drawCircle.
> What if you want a draw method that takes a thing and a backend, then
> you need if statements again, draw(self,backend): if backend ==
> postscript do one thing else do another.
> Maybe you can solve this with multiple inheritance, creating
> RectangePostscript and CirclePostscript objects. Lisp supports multiple
> inheritance too, but also multimethods which allow a looser coupling
> between objects and dispatching on all parameters, not only the first
> parameter (self in python speak). Just define one method
> draw(rectange,postscript) and another draw(rectangle, pdf)

This mechanism doesn't make much sense in Python since dispatching based
on type rather than on capability is considered "bad" in the Python
world, and for good reason. 
The classic example is file-like objects.  What if you have two methods,
one that takes a file object and another that takes a string and you
pass an object that has string as a base class but provides file-like
capabilities?  Which method should be called?  Better to explicitly call
the desired method.  Multimethods may make sense in many languages but
not so much in Python.  

Regards,
Cliff





More information about the Python-list mailing list