From: Sean O'Dell Date: 2003-11-21T12:14:01+09:00 Subject: Re: "stereotyping" (was: Re: Strong Typing (Re: Managing metadata about attribute types) ) On Thursday 20 November 2003 06:47 pm, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: "stereotyping" (was: Re: Strong Typing (Re: Managing > metadata about attribute types) )" > > on 03/11/21, Chad Fowler writes: > |matz, how do you define "interface"? In sean's case, class and/or module > |were sufficient to define interface. This is majorly what I take issue > |with. If "interface" is really a collection of "respond_to?" > |requirements, then I can start to stomach the idea of it being added to > |Ruby (I believe you were proposing something similar in your RubyConf > |presentation). > > I just don't know. Only things I can tell you now are: > > * Types (or "interfaces" to avoid confusion) must be independent > from class/module, otherwise they will be misused too often. Note > that Sean himself once failed to distinguish these two. I agree, but since classes and interfaces are often synonymous, there could, possibly, be an alternative mechanism to describing interfaces that used class definition in some way. > * I'm sure I don't fully understand his new proposal in > [ruby-talk:85888], but if it is statically checked at compile time > as he explained, I wonder how much it is effective. We have many > cases where that kind of "static interface check" would not cover, > thus make it "false promise". I still need to examine his > proposal to make the final decision. Please ask me questions. I'm terrible about making my own new ideas known because I don't anticipate how clearly they will be received. The way "false promise" was used before, a class could say "I implement this interface" and then NOT implement it, making the statement a lie. In my new proposal, there is no way to make that statement. If a class declares "I implement this interface" it is marked as "incomplete" and the declaration is essentially hidden until the last method fulfills the interface requirement. The class makes the statement, but that is basically ignored until fulfillment is complete, and then the class can generate objects which contain a flag for that interface. > * The appearance matters. I think the code example in the proposal > does not look like Ruby: > > class Stdin > def Boolean eof? > return is-at-end-of-file > end > def Integer read(Integer maxbytes) > return bytes-read > end > end > > I'm not sure how to design the interface syntax in the Ruby Way. That was just an example, I threw that in quickly. Perhaps the interface requirements would appear in the interface definition, but they would not be repeated when the class actually defined the method. Sean O'Dell