On Sunday 06 June 2004 03:25, Mauricio FernŠŌdez wrote:
> On Sun, Jun 06, 2004 at 09:36:25AM +0900, Sean O'Dell wrote:
> > This is the solution I am going with now.  In fact, if Ruby itself had
> > this sort of "interface identification" built-in, it would suit me
> > perfectly.  I don't believe that respond_to? really tells you much about
> > an object's interface.  Two objects can respond to the same method name,
> > but do COMPLETELY different things.  Duck typing doesn't work, and
> > checking respond_to? doesn't work.  The only way to REALLY know if an
> > object implements a certain interface is if you can positively identify
> > it directly. Somehow, the object has to say "I implement the hash
> > interface."  Whether that's just a simple flag, or if Ruby can somehow
> > match it's methods to an
>
> A protocol imposes constraints to the acceptable behavior of the object, so
> as you correctly pointed out, the signatures alone can't suffice. I
> believe the current state of the art can discover many implicit
> invariants in the code, but it can't infer them all. Even if it could,
> at some point you might have some invariants that hold only due to the
> particular implementation used, it is still up to the programmer to
> specify whether some invariant belongs to the interface or is just a
> coincidence.

No constraint is necessary, an interface is just a declaration.  A complete 
native description of the interface allows a language to do some compliance 
checking, but not much.  Compliance can be broken in many languages through 
poor implementation, and by overriding individual methods and changing their 
purpose and number of parameters.  The idea here isn't to get 100% positive 
compliance (that's impossible), but to merely identify when an object THINKS 
it is in compliance.  That is absolutely sufficient.  It suffices in C++ and 
Java just dandy.  You can derive a C++ class and completely divert from its 
functionality, and pass an object of that class to functions that take 
objects of the base type, and the function will fail miserably.  You can't 
prevent every possible discrepancy.

	Sean O'Dell