[Python-Dev] Re: Reiterability

Phillip J. Eby pje at telecommunity.com
Mon Oct 20 14:31:24 EDT 2003


At 10:08 AM 10/20/03 -0700, Guido van Rossum wrote:

>I'm all for adaptation, I'm just hesitant to adapt it wholeheartedly
>because I expect that it will have such a big impact on coding
>practices.  I want to have a better feel for what that impact is and
>whether it is altogether healthy.  IOW I'm a bit worried that
>adaptation might become too attractive of a hammer for all sorts of
>problems, whether or not there are better-suited solutions.

FWIW, it occurred to me recently that other languages/systems (e.g CLOS, 
Dylan) solve the problems that adaptation solves by using generic 
functions.  So, by analogy, one could simply ask whether generic functions 
are too attractive a hammer in those types of languages.  :)  The other 
comparison that might be made is to downcast operations in e.g. Java, or 
conversion constructors (is that the right name?) in C++.

In some ways, adaptation seems more Pythonic to me than generic functions, 
because it results in objects that support an interface.  To do the same 
with generic functions, one would have to curry in the "self".  OTOH, 
generic functions in CLOS and Dylan support multiple dispatch, which is 
certainly better for implementing binary (or N-ary) operations.  So there 
are tradeoffs either way.  Sometimes, when I define an interface with just 
one method in it, it looks like it would be cleaner as a generic 
function.  But when there's more than one method, I tend to prefer 
interface+adaptation.  I don't have a generic function implementation I'm 
happy with at present, though, so I stick with adaptation for now.

One other issue with generic functions is that languages with generic 
functions usually have open type systems that allow e.g. union types or 
predicate types.  Python doesn't have that, so it's hard to e.g. "adapt 
from one interface to another" with generic functions.  It can be done, 
certainly, it's just hard to do it declaratively in a manner open to extension.




More information about the Python-Dev mailing list