From: nathaniel@... Date: 2003-04-12T22:40:22+09:00 Subject: Re: Does dynamic typing make it easier to place an object in a container? Ryan Pavlik [mailto:rpav@nwlink.com] wrote: > This message has gone on far too long already, but I'll address the > question in the subject line shortly. With OOP, as you can refer to > an object by a generic parent class, it's really no more difficult > in a static language to make a container than in a dynamic one. > Either way you can filter your classes to make homogenous containers, > or allow heterogenous containers. Ahem. I beg to (gently) differ. I program in Ruby and in Java on a regular basis, and it is much more difficult to use containers in Java than it is in Ruby. For example: a = ["1", 2] a.each {|number| puts(number.to_i * 2)} vs. Collection a = Arrays.asList(new Object[] {"1", new Integer(2)}) Iterator iterator = a.iterator(); while(iterator.hasNext()) { Object thing = iterator.next(); int number = 0; if(thing instanceof String) number = Integer.parseInt((String)thing); else number = ((Integer)thing).intValue(); System.out.println(number * 2) } Now, one thing that would lessen some of the pain would be generics (which C++ has, and Java will have in 1.5). However, generics only really help when I have a set of things that respond to a common interface, and that wouldn't help in this case because I can't modify String and Integer in Java to implement a common interface. Of course, I could always implement my own, smart Collection in Java, right? Sure, and implement 20 methods I don't give a rip about. I guess my point is that in theory you can say "it's really no more difficult in a static language to make a container than in a dynamic one," but it sure does seem a lot harder in practice. Sure, Eclipse will generate most of that code for me, but I think if you took out the generated stuff, it'd still be more than the equivalent Ruby code. On the confusion between dynamic vs. static and weak vs. strong typing, I agree that it's easy to get them confused. As I was thinking about it, I remembered something about the word dynamic, though: French dynamique, from Greek dunamikos, powerful, from dunamis, power, from dunasthai, to be able. So when you think of Ruby, think of Strong and Powerful. Of course, that led me to wonder about the root of static... New Latin staticus, relating to weight, from Greek statikos, causing to stand, from statos, standing. So one might think of Java and C++ as being Strongly Stuck in the Mud from their own Weight ;-). Nathaniel <:((>< + - - | RoleModel Software, Inc. | EQUIP VI