From: Ryan Pavlik Date: 2003-04-13T01:29:12+09:00 Subject: Re: Does dynamic typing make it easier to place an object in a container? On Sun, 13 Apr 2003 00:49:00 +0900 "Brett H. Williams" wrote: > On Apr 12, Ryan Pavlik wrote: > While I agree with your statement about the lowest common denominator, > I must disagree from a practical standpoint. Do you commonly treat > objects as void * and pass them around as such in C++? I hope not. Actually, I make a standard base class, Object, and inherit from there. Basically works the same way as in Java. Given multiple inheritance, I can pull in other classes if necessary. > In Java, however (at least until 1.5 comes out and is widely > distributed), much of the time you _do_ in fact pass things around as > Objects due to the containers, just like Dave's note above. I do too. It's quite necessary in reclaiming some lost abilities in static languages when doing OOP. > The "lowest common denominator" you refer to is very common in Java. > > > These language features all let you do some things similar to dynamic > > typing or weak typing, but that doesn't make the language dyamically > > or weakly typed. > > Not literally. But some of the advantages of static typing are in > practice diluted when using collections in Java. And what program > doesn't make heavy use of collections? I think that was the > point--the headline to the note is more for drawing attention to it. This is merely somewhat of a tick against static typing. It shows, as you've pointed out, that to do something practical, you end up diluting it. But it's still static. > Very commonly these advantages are reclaimed by extending the > collection class and automating the casts within that class. But this > is a pain, particularly if you need your collection to perform these > casts for a complete interface (as opposed to just overriding the > methods you care about). That would be painful, too. Silly, in fact. I dislike anything that requires the programmer do manually what the computer could do trivially by itself. That's why I'm a fan of dynamic languages. ;-) > Perhaps in theory, or in some languages (I can't speak for what I > don't know)--but not in C++ or Java, which is likely what the original > article was referring to. It is more difficult to use containers in ^^^ > those languages. You either use the generic parent class (Object in > Java, except that doesn't work with int, char, float etc, another step > must be taken) and cast, or create some templates in C++ (there is no > generic parent class). Neither of these are even close to being as > easy to do as a = [ "1", 2 ]. Possible, and certainly commonly done, > but not as easy. Again, my original statement was regarding the creation of the container---implementation, not instantiation. As for instantiation, in C++ anyway, you could have it no more complex than this: a = new Vector; a << new String("1"); a << new Integer(2); I do not hesitate to agree this is quite a bit of work, and it's not as easy to use as a dynamic language. I dislike static languages, merely from the standpoint that they make certain abilities of OOP useless, and they lead to me (the developer) doing more work. > > Just my $.02. > Mine too ;) -- Ryan Pavlik "My plans are *always* practical! It's the laws of physics that get in the way of my success." - 8BT