From: Ilan Berci Date: 2007-04-04T00:27:55+09:00 Subject: Re: New presentation on Ruby Chauk-Mean P wrote: > > As stated in slide 15 : > - I just said that Java untyped collections or generic collections for > type > Object DO support heterogeneous types. > But the drawback is that you NEED to downcast a retrieved element. > - Conversely, if you use a generic collection for a type X (e.g. > TalkingAnimal) different than Object, you can put only objects of type > X. > You cannot put an object that is not of type X (e.g Rabbit2) > You avoid most downcasts for retrieved elements. Thus you can retrieve a > TalkingAnimal and call talk. > But if you put an object of type Y that extends the capability of X > (e.gDuck2) and you want to call a method of Y ( > e.g. walk), then you need to downcast to Y. > > Tell me what is wrong about that ? > Chuck, please update your java from 1.4 to 1.5JDK (5.0) and check out generics, there is no longer a NEED(why the upercase?) to downcast from containers as it's done for you. It is a far cry from c++ templates that are done at compile time but it still alleviates the need for downcasting. class SomeThing { } java.util.Vector noNeedForDownCastingVector = new java.util.Vector; for your viewing pleasure: http://java.sun.com/j2se/1.5.0/docs/api/ I also fully realize that I didn't hear the talk that went with the slides but you asked us for feedback on the slides knowing that we didn't hear the presentation. Be carefull what you wish for especially on this list.. As for your example on duck typing, I can illustrate the same thing in your slides by doing an exact port in Java which is known not to support duck typing (message passing) class Duck { public String quack() {return "quack";} } class Bird { public String quack() {return "chirp";}} d = new Duck(); d.quack(); b = new Bird(); b.quack(); // does this mean java supports duck typing too?? It does if we go by your slide or C++ struct Duck { void quack() {cout << "quack";}} struct Bird { void quack() {cout << "chirp";}} Duck().quack(); Bird().quack(); // Wow.. guess this means c++ supports duck typing too.. i.e. My point was in order to illustrate the construct, you must use a temporary variable! As for private methods in class Object, you are correct sir and I stand corrected.. As for Erlang, it has simply nothing at all remotely to do with Ruby. It's a seperate beast entirely and it appeared from your slide show that you were utilizing it to promote Ruby based on a small subset of functional programming. It's kind of like saying that the language Ruby is spelled exactly like the gem and we all know how shiny the gem is so Ruby must be shiny by extension. Actually come to think of it, I think Ruby has more in common with a gem than it has with Erlang. I experimented with Erlang from the urging of my former boss and suffered from severe headaches, brushes with suicide, weight gain and halitosis.. I am hoping the new pragmatic book will enlighten me but one thing I can atest to is that it's far removed from Ruby and the only time thy should be used in a sentence together is the following: "Ruby starts with an 'R' and Erlang starts with an 'E' " ilan -- Posted via http://www.ruby-forum.com/.