"stereotyping" (was: Re: Strong Typing (Re: Managing metadata about attribute types) )

In sean’s case, class and/or module were sufficient to define
interface. […] He goes on to say the same re: inheritance
and module inclusion.

To be fair, he goes beyond class/module model. The reason we tend to object
to the class/module model of interfaces is that things like StringIO, which
has no module or inheritance relationship with IO, tends to be used in
places where an IO object is expected.

But Sean also proposes an interface command that can be used to indicate
non-class/non-module conformance. You can say …

class StringIO
interface IO
end

The interface command adds IO to a list of supported interfaces for the
StringIO class. It gets no implementation from IO, nor does it inherit from
IO. The interface command is just there so that any conformance testing on
a StringIO object can say “Oh look. This object claims to be able to do
whatever an IO object would do”.

This decouples conformance from mere class inheritance/module inclusion,
although class inheritance and module inclusion still count as conformance.

I haven’t decided whether I like this or not. Right now I’m kinda neutral.
It avoids the problem of decreased flexibility at the cost of an extra line
of code.

···


– Jim (still thinking about it) Weirich

I don’t like it because it’s an empty promise.

class Foo
interface IO
end

Now, if I try to use Foo somewhere, I’ve promised that it can do IO – but
it can’t. I haven’t implemented any of the methods required to do so.

It also doesn’t get us any closer to the concept of signature metadata,
which despite my misgivings about wanting “contractual obligations”, I
believe Ruby needs for exposing programs to non-dynamic languages over wire
protocols.

-austin

···

On Fri, 21 Nov 2003 08:07:34 +0900, Weirich, James wrote:

I haven’t decided whether I like this or not. Right now I’m kinda
neutral. It avoids the problem of decreased flexibility at the cost of an
extra line of code.


austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.11.20
* 19.19.29

I haven’t decided whether I like this or not. Right now I’m kinda
neutral. It avoids the problem of decreased flexibility at the cost
of an extra line of code.

I don’t like it because it’s an empty promise.

Until I know that Object (or Foo, elsewhere, for that matter) hasn’t had
method_missing redefined to catch read(bytes) and do something sensible
with it self.kind_of?(Foo), I can’t declare the below to be an “empty
promise”… :wink:

class Foo
interface IO
end

Now, if I try to use Foo somewhere, I’ve promised that it can do IO –
but it can’t. I haven’t implemented any of the methods required to do
so.

Then allow interface to check for required methods.

(And IMNSHO, IO would be a useless interface - it’s far too broad for at
least 80% of cases. It should be broken down into at least
IOStreamRead, IOStreamWrite, IOStreamSeekable and possibly more.
Although interface combinations might be useful.)

It also doesn’t get us any closer to the concept of signature
metadata, which despite my misgivings about wanting “contractual
obligations”, I believe Ruby needs for exposing programs to
non-dynamic languages over wire protocols.

I don’t follow. If I write a library which operates on or with a
complex (ie. non-built in type), then I need to define how this complex
object should behave in terms of required methods. The best mechanism I
have seen anywhere in any language for doing this is an interface.
However traditional interface constraints (as per staticly typed
languages) might limit usefulness of such a feature in a language as
dynamic as Ruby, so a softer (probably runtime) approach would be more
in keeping with existing language features and checks.

That said, in the interests of programmers who use irb for documentation
and reflection in general, it is also highly desirable for the
expectations and provisions of an interface to queryable from Ruby code.

And it does get us closer - not all the way to a C function declaration,
but closer to a workable and rubyish contractual obligation between
classes.

TTFN,

Geoff.

···

On Fri, Nov 21, 2003 at 09:21:42AM +0900, Austin Ziegler wrote:

On Fri, 21 Nov 2003 08:07:34 +0900, Weirich, James wrote:

well, apart from more Rubysh names (like Input and Output)
I strongly agree with you.

em… cough…rcr…cough

···

il Fri, 21 Nov 2003 10:53:21 +0900, Geoff Youngs g@intersect-uk.co.uk ha scritto::

(And IMNSHO, IO would be a useless interface - it’s far too broad for at
least 80% of cases. It should be broken down into at least
IOStreamRead, IOStreamWrite, IOStreamSeekable and possibly more.
Although interface combinations might be useful.)