Sean O'Dell
11/21/2003 2:59:00 AM
On Thursday 20 November 2003 06:07 pm, Greg McIntyre wrote:
> "Sean O'Dell" <sean@celsoft.com> wrote:
> > On Thursday 20 November 2003 04:37 pm, Greg McIntyre wrote:
> > > I like your idea, Sean, but it's too much effort! If it is onerous
> > > then it won't be used. Perhaps if we based it upon method name and
> > > arity(essentially replacing a bunch of respond_to?() calls with
> > > arity checks added in as a bonus). This is because it requires no
> > > extra effort on the programmer's part, so it fits into the existing
> > > Ruby syntax.
> >
> > Very funny. =)
>
> Gee, I wasn't trying to be funny. I really would be annoyed if I had to
> write as much as you did to have interfaces. A lot of what you would
> end up writing would be repeditive, in the same way that with C++,
> writing .h and.cpp files repeats a lot of information (i.e. the type
> signatures).
Oh, you didn't mean it? Oops ... I saw a close resemblance between your code
and something someone else proposed, and your suggestions were so far from my
proposal, I thought you were ribbing me!
Anyway, how little can you write to describe an interface? I mean, somewhere
you have to write it out. It can't be avoided. Someone has to put the
requirement down in type somewhere. If it's not the interface designer, then
the developers have to ask for their requirements. I think the least amount
of typing is a situation where the interface designer types it out once,
gives it a name, and developers just refer to it by name thereafter.
> > Actually, I sort of meant my proposal to require a very minimal effort
> > for both sides. On Matz' end (save for syntax sugar) it's not a heck
> > of a lot to code, and it doesn't screech hard against the existing
> > code (at least not from what I've seen, could be wrong), and on our
> > side it's just a short block of interface description to write. It
> > really couldn't get a heck of a lot easier except to just not do it,
> > or to do some sort of interface id tagging thing like my first
> > proposal, where no enforcement was performed at all.
>
> The main problem I see, with both versions, is that they put the onus on
> the class provider to define all supported interfaces, whereas use of
> respond_to? puts the onus on the class client to assert the object
> supports the minimally required interface. Where _should_ the
> responsibility be? If it's up to the provider then the client may end up
> with an object which does not promise to support an interface it could
> because it is ignorant of it: i.e. it may restrict duck typing. If it's
> up to the class consumer then all that checking becomes a pain (and
> inefficient). Hmm...
I think when you are talking about interfaces, you are describing a contract,
and that goes to the interface designer.
> Can you clarify your idea in the following regard?
>
> Can I check one object against another's interface at run-time if I
> desire it?
>
> def read_from(object)
> if object.complies(IO::InputStream.interface)
> # ...
> end
> end
Yes, if you didn't use syntax sugar to tell Ruby to please enforce that object
completely fulfilled the IO::InputStream interface, you could ask
object.implements?(IO::InputStream) (which is how I think my proposal worded
it, but yours is equivalent).
> At "definition" time, yes (when the class is defined). Isn't that what
> your code does? Ruby has no "compile" time, after all...
Yes, that's when I mean.
> > I mean, there will always be respond_to? and for those people who see
> > no use in interface checking, they can, as always, keep just asking
> > respond_to? or not asking anything at all. Your changes seemed to be
> > sort of a souped-up respond_to? engine.
>
> Yes, that's a good way to describe it... which is interface checking. :)
> It's just that the interface contains a little less information than the
> type signatures of statically typed languages.
Yes, my proposal did not say anything about the end developer any way to ask
about the types required. But if Matz does the internals for interface
checking, he can also add methods to the Method class to do that sort of
thing. Internally, he's going to have to come up with some way to encode
method names, parameter numbers and interface requirements into an nifty,
easy-to-use internal structure. The information in that structure can be
exported back to Ruby in any number of ways. I think it comes with the
territory eventually. I think discussions about that would be down the line,
and lots of nifty ideas could surface.
> In practice (and we've had a decade of it), Guido and matz have shown us
> that we don't really need such strong type safety -- it's a frictional
> force while programming and the difference it makes in practice is
> minimal.
People have their reasons for wanting it, though, as do I. I think there are
a myriad of reasons they would be good, and I can list them all, and others
can add to the list, but ultimately those reasons can be argued down. I
don't think any way to do anything is imminently set in stone; almost
everything has a work around.
> You'd probably want to allow explicit interface definitions too, I just
> think you're creating more work for yourself if you ingore what you
> already have...
I think the problem is partially that we don't have enough type information to
try anything with, just to see, so we need something to start down that path.
Once it's there, we can see where else such information would be useful.
Ultimately, though, I think interfaces will be their most important use. Some
people will still do things by querying one method at a time, getting a
little more information than they were before.
> > My proposal does all the interface fulfillment checking at
> > compile-time, then conformance checks are done with a simple flag test
> > internally.
>
> I thought my suggestion would too. It's based closely upon your
> suggestion after all... I just "Rubied" the information you keep in your
> interface so it did not tread on the pretty ducks. ;)
In your modification, you were building these arrays every time, and then for
conformance, I assume Ruby would have to do an array-to-array comparison to
determine compliance. It's sort of the same thing, but since that would
happen constantly at run-time, I think it's probably more overhead than we're
aiming for. But yeah, it's definitely the same thing.
Though, of course, the method information could be reported in a similar way.
I guess we'd have to look at the interface implementation to tell what we can
and can't report back.
Sean O'Dell