From: Ryan Pavlik Date: 2003-11-08T11:43:56+09:00 Subject: Re: Strong Typing (Re: Managing metadata about attribute types) On Sat, 8 Nov 2003 11:29:11 +0900 "John W. Long" wrote: > My real question is more: Is there a better way to implement Strong Typing > so that people will not tend to use it in the wrong way? > > I'm thinking of something along the lines of: > > def my_method(a, b, c) > expect a to implement this behavior #this seems more ruby like > expect b to implement > ... > end > > This is essentially what you have written. However it is also easy to > implement it in a way more like statically typed languages: > > def my_method(a, b, c) > expect a is a String #this is more like basic, java, or c > expect b is an Integer > ... > end > > Most of the reaction seems to be against the second option. The problem is people seem to think that "implements String behavior" and "is a String" are two different things. I'm not sure why. If it is a String, then it implements a String behavior by definition. If it doesn't implement a String behavior, then it's not a String. What's wrong with calling something what it is? "Duck typing" acts in just this way: if it implements the behavior of an object, then we consider it that object. Except with "duck typing", it's just blind to the little detail of whether it's actually the behavior you expect or not. Confusion also seems to be around the fact that type checking is static typing. Or that strong typing is static typing. It's been repeatedly shown that this is not the case, but people persist under this assumption. Just recently I've seen the strongtyping module referred to as the "statictyping" module, which is completely wrong. The fact that people don't understand this difference limits them. Getting back to the point at hand: if something implements the behavior of a thing, we call it that thing. We already have a mechanism---classes and modules---for doing so. Multiple inheritence, which Ruby implements in a certain form, allows us to call an object any number of accurate descriptions. There's just no need to reimplement a wheel that we already have. -- Ryan Pavlik "If we can hear your internal monologue, then it *isn't*." - 8BT