typetesting, adaptation, typeclasses, ... (was Re: isinstance() considered harmful)

Jason Orendorff jason at jorendorff.com
Fri Jan 25 13:02:51 EST 2002


Alex Martelli wrote:
> Jason Orendorff wrote:
> > [However, I can do without recursive definitions.  Usually,
> > one operation is the primitive and the others are sugar.
> 
> Actually, it's more frequent that two (occasionally more)
> operations need to be in a certain connection with each other,
> but none of them is 'intrinsically' primitive wrt the others.
> 
> Having to arbitrarily pick one of .append and .extend as
> "more primitive" in the definition of a list typeclass is
> quite inelegant, for example.

You're treading dangerously close to preferring a mathematician's
sense of elegance to a programmer's sense of clarity.
I'd guess that for the ordinary programmer, append() feels
more primitive (perhaps because it deals with atoms and not
molecules; and perhaps because it's used more often).

Actually I guess I would define extend() in terms of
__setitem__(self, slice), and append() in terms of insert().

I wouldn't bother defining __setitem__() in terms of
insert() and __delitem__().  It just seems a bit much to me.

> I guess this boils down to aesthetic style preferences [...]

Yeah, pretty much.  (C:

Anyway, in Java the idiom is to provide an interface and
then provide an abstract base class that implements most
of the interface (recursively, if you like; I think some
java.io class does this).  This means you can't add methods
to the interface later, but it's still IMHO more useful
than what Python has (no explicit interfaces at all).

## Jason Orendorff    http://www.jorendorff.com/





More information about the Python-list mailing list