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

Jason Orendorff jason at jorendorff.com
Thu Jan 24 23:13:16 EST 2002


Alex Martelli wrote:
> You don't need EVERY method -- you only need the methods you need.  If
> you never call x.extend, for example, why put x's author to the useless
> burden of implementing extend?

-1

This makes your function less of an abstraction.  The caller
now needs to know exactly which methods you're going to use.

Better to define an interface and ask people to implement it.

I like interfaces with default implementations:

  interface wfile:
      def write(self):
          pass
      write = abstractmethod(write)  # syntax could be better (C:

      def writelines(self, lines):
          for line in lines:
              self.write(line)

      def flush(self):
          pass

[However, I can do without recursive definitions.  Usually,
one operation is the primitive and the others are sugar.
But even if not, it is still redundant to define x() in terms of
y() and also define y() in terms of x().  Either definition
alone suffices to illustrate the relationship.]

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




More information about the Python-list mailing list