From: Dave Thomas Date: 2001-02-23T01:31:36+09:00 Subject: [ruby-talk:11327] Re: musings about Hash#each_with_index jmichel@schur.institut.math.jussieu.fr (Jean Michel) writes: > >Arrays and hashes have similar properties, but are different beasts, > >In the same way that the old OO argument of Squares and Rectangles > >can't be resolved by answering a Square is a kind of Rectangle, or a > >Rectangle is a kind of Square, so too is it impossible to say that an > >Array is a kind of Hash or a Hash a kind of Array. It seems to me that > >they just share some properties. > > Watch out here! The fact that you can consider an array as a special > case of a hash, of for that matter a string or a file or a directory as > a special case of an array is much more than just an analogy. The set of > properties which is shared in these cases is an extremely important > programming paradigm, and a language which can express clearly this > paradigm in a uniform way in all cases will have a definite advantage. I > think the mixins that matju is trying to make can potentially achieve > this for Ruby. I agree it's an important paradigm: interfaces are the best thing about Java. I'm just not convinced it's a necessary paradigm. A couple of years ago, I'd have been on your side. I was a strong typing bigot, and wanted everything tied down. Now I'm learning that it's OK to rely on the fact that an interface is defined by the messages that an object happens to accept at runtime, and that (for example) using '<<' as a "write to the end of" operator works just fine without having to define a "write to the end of" interface. I see matju's work differently. I don't see it constraining existing behavior. I see it as 1. A quick way to generate new classes which ape the behavior of built-in classes, and more importantly 2. A step towards Ruby-in-Ruby/microRuby or whatever it's called this week. Regards Dave