merits of Lisp vs Python

George Sakkis george.sakkis at gmail.com
Mon Dec 11 17:08:20 EST 2006


Cliff Wells wrote:

> 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.

Actually they do in Python too, and there's a long active discussion in
the Python 3K list about whether should generic functions (aka
multimethods in Lisp) be added in the language and how they blend with
other concepts that compete in the same arena (interfaces, abstract
base classes, etc.). Generic functions are available even today from
the PEAK framework; see for example
http://www-128.ibm.com/developerworks/library/l-cppeak2/.

George




More information about the Python-list mailing list