[Types-sig] File Protocol Proposal

Marcin 'Qrczak' Kowalczyk qrczak@knm.org.pl
14 Mar 2001 21:47:27 GMT


Wed, 14 Mar 2001 12:50:37 -0500, Barry A. Warsaw <barry@digicool.com> pis=
ze:

> We may need to add a boolean type to Python.

I agree. But I'm afraid that if Guido wanted it, he would add it
earlier.

> Say a method takes an object that must have a read([size]) method.
> That's all you care about.  Yes, you could define an interface
> that describes this, but what if someone passes in an object that
> conforms to a full blown "ReadableFile" interface -- i.e. it provides
> read([size]), readline(), readlines(), and maybe seek()?

Of course the system must be designed to make this work.

> Let's say those two interfaces are defined in unrelated and
> separately authored libraries, but I'm writing code that combines
> the two.  Library B gives me a factory that produces ReadableFiles
> and I'd like to pass those to library B's method that specifies a
> MustHaveRead interface.
>=20
> Am I screwed?

Depending on whether we do it right :-)

Other languages I know solve it either:

- by declaring that ReadableFiles conform to the MustHaveRead
  interface; this can be done *outside* to the definition of
  ReadableFiles, because MustHaveRead requirements can be fulfilled
  basing on the public interface of ReadableFiles; or

- by using "name equivalence" instead of "object identity" for
  determining if both 'read' methods are really the same thing;
  this is how it works in Python and Smalltalk, although without
  static checking: protocols are defined by names of methods and
  are not declared.

> ReadableFile's interface is a superset of MustHaveRead so it should
> be fine, but because the interface objects aren't explicitly related,
> you're hosed.

Indeed. The system must not require ReadableFile to know about
MustHaveRead. Let's not repeat Java's mistakes.

--=20
 __("<  Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZAST=CAPCZA
QRCZAK