On 20.04.2008 12:52, Florian Gilcher wrote:
> On Apr 20, 2008, at 7:15 AM, thufir wrote:
> 
>> On Sun, 20 Apr 2008 07:49:02 +0900, Joseph Lenton wrote:
>>
>>> As far as I've understood it, in Ruby it's not about what the type is
>>> but what the type can do. i.e. does it respond to a specific  
>>> method. So
>>> maybe generics in Ruby would make sense if you could restrict objects
>>> based on what they can do. For example an array which can only hold
>>> obejct that respond to the to_str method.
>> Right; I'm taking a Java course which will be covering Generics and,  
>> in
>> Java, this a big part of the point of Generics:
>>
>> an array which can only hold objects which implement a specified
>> interface.
> 
> Arrays are not the interesting thing when it comes to Generics. (As  
> Arrays in Java
> already force every Element to be of the same type)

He probably meant ArrayList instead of array...

> The interesting thing about Generics in Java (and the point where they  
> cannot make
> sense in ruby) is that they are only checked on _compile_ time. So, at  
> runtime, all
> generic collections behave as a collection of Object.
> 
> The difference between Generics and Templates in C++ is that C++  
> generates one
> Class for each used Template+Type 

Templates are not restricted to classes.  You can also have templated 
methods.  There are other differences for example partial 
specialization.  There are some nice articles around about the 
differences, for example
http://www.mindview.net/WebLog/log-0061
http://www.cs.binghamton.edu/~mike/presentations/java-generics-cs580c-fall-2007.pdf

> while Java only generates one (that  
> actually
> doesn't care about the type anymore).

Actually Java generics do not generate types at all.  The only thing 
that they generate - if you will - are automated casts.

> This technique is called "Type  
> erasure", because
> the type information gets erased after it was compiled.[1]

Exactly.

> All this doesn't make any sense in Ruby, as there is no real 'compile  
> time'.

Absolutely.

Kind regards

	robert