From: jmichel@... (Jean Michel) Date: 2001-01-22T20:10:02+09:00 Subject: [ruby-talk:9710] Re: 101 Misconceptions About Dynamic Languages Christoph Rippel wrote: >math-ruby ml - the lag of generics is almost staring at you. In C++ you would >implement something simple like ZZ/(n) (sorry for the math lingo) > >class ComRing { >// maybe create a top abstract class >}; > >template >class ZZ_mod : public virtual ComRing { >static const unsigned int N = n; >// implement constructors and arithmetic operations >// which depend on the class constant N. >}; > >try to express this in Ruby - it is going to be a nightmare. There are a lot of >competent people who consider a lack of support for generics as a language >deficiency - for example support for generics in java Here I must make a comment; I know a lot more about programming mathematics than you do; it has been one of my main activities for the past 25 years. The functionality you want is to describe a mathematical structure, such as a ring; the basic idea is that, as soon as certain operations and fields are defined, you can define certain other ones. A template in C++ expresses perfectly this, but also a mixin in Ruby. The only thing missing in Ruby here is the ability to overload on argument types; this was circumvented by a hack around 'coerce'. Otherwise Ruby is fully equivalent in expressiveness to C++. Now, there are problems in the actual library and class design in Ruby: I think too many things are classes were most of the functionality should have been put in mixins: most operations on arrays or hashes should have been put in mixins, and class IO should have been a mixin (this came up recently in a discussion about doing the perl equivalent of 'tie' a hash: if most of the hash methods has been in a mixin the implementation would have been very easy, where in contrast now one has to copy a lot of methods whih are trivially implemented in term of others). Actually I think it is still not too late to reform Ruby by pushing the functionality in mixins. As far as I can see this would change the language in a perfectly upward compatible way. Best regards, Jean MICHEL