Hi,
A class has interface; a class can be used as interface (by set of its
methods); but it should not be checked by kind_of? or anything based
on inheritance, just because it hinders flexibility of dynamic typing
so much; remember StringIO or tempfile examples.
But again, that flexibility is LOST when you have to pass an object to a
method that REQUIRES it to behave a certain way. The flexibility is
already gone; it wasn’t eliminate by a language quirk, it was eliminated
by the need of the method being called.
I’m not sure what you mean by “flexibility LOST”. In your scenario in
[ruby-talk:85611], certainly it is much easier to tell that your
library is requiring Socket interface, but without that kind of
interface check, no flexibility is lost, it’s little bit hard to find
out the semantics.
When a method is written to use the methods of another object, and that code
is distributed as a library, the function of that method is fixed. You must
pass it an object that has the methods it requires, and those methods must
take the exact parameters it expects.
The flexibility to change the method of the object is lost. You cannot change
the parameters to the “send” method of a Socket object and pass it to a
library that uses it. You will get an error deep inside the library.
The flexibility was removed by the library developer. At the point of
calling, the object MUST conform.
Maybe we are referring different “flexibility”. Mine is the one that
allows replacing IO by StringIO. Currently we have no language
support to check nor enforce them, but it’s still possible, not lost.
This is fine. This is what I want. If I write a method that can accept File
or StringIO, I want to write a method that asks “does this object implement
the IO interface” and if the answer is yes, then continue. Anyone can also
write a class that implements the IO interface and pass an object of that
class to my method. All I care about is “does this object implement this
interface?”
I’m only talking about checking that a certain interface is present. Just
for the purpose of providing an informative error message when an object
which cannot fulfill the needs of a method is passed. Right now, it just
explodes with an ugly message about something that happened deep in the
called method. Something more informative would go a LONG way.
Reconsider, Matz.
Reconsider what? I didn’t tell you any decision yet. I’m still
the level of seeking what you mean.
You said the following:
I admit type checking can gain you something, at the cost of
flexibility, which I don’t want to pay in Ruby.
You don’t want to pay the price of type checking in Ruby. My version of it is
really “interface checking,” but either way what you said sounds like you’ve
decided you don’t want to pay the price for any of this.
Sean O'Dell
···
On Wednesday 19 November 2003 12:47 pm, Yukihiro Matsumoto wrote:
In message “Re: “stereotyping” (was: Re: Strong Typing (Re: Managing > metadata about attribute types)” > > on 03/11/20, “Sean O’Dell” sean@celsoft.com writes: