From: Jim Weirich Date: 2003-11-19T22:09:10+09:00 Subject: Re: "stereotyping" (was: Re: Strong Typing (Re: Managing metadata about attribute types) ) > On Wed, 2003-11-19 at 10:30, Weirich, James wrote: >>This perfectly reasonable use of read will fail because StringIO does not >>enherit from IO, even though it implements IO-like methods. This is a >>shame. Our "type-checking" has needlessly constrainted our solution. Simon Kitching wrote: > I think this is a flaw in the current ruby libraries, not a flaw in the > concept of typechecking. [...] > I suggest this approach: [... redesign of Ruby class libraries to support abstract IO objects elided ...] An interesting suggestion, but I still feel it still over constrains the problem. For example, what if I had an input only device. If I include the IO module then I am lying about its capabilities, but if I don't include IO, then I can't use it in functions that read from IO objects. Over constraint. I suppose we can redesign the IO libraries again to reduce it to InputIO and OutputIO classes, but then I would ask about sequential IO vs random access IO. The logical conclusion of this exercise is a plethora of IO modules, each covering a small subset of the IO capability. Look at the Java IO library for an example of that. > Note that checking for *concrete* classes using is_a is a totally > different issue. That does present problems regarding the inheritance > tree, because you can't just mix in such a type to any other type. I > think the arguments against this pattern are on much stronger ground. > > Comments? I will agree that abstract module markers are not as onerous as testing for concrete classes, but they still carry significant design overhead, impose a runtime overhead and still do little to actually guarantee that the desired behavior actually exists. -- -- Jim Weirich jweirich@one.net http://onestepback.org ----------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)