From: "David A. Black" Date: 2008-05-01T06:25:26+09:00 Subject: Re: Typed ruby Hi -- On Thu, 1 May 2008, Joe K wrote: > >> I think programmer sanity is probably helped by not having such a >> `feature'. Reusing variables for different purposes is not at all what >> [not] `typing' is about, and as David suggested, you possibly mean class, >> not type. (singleton methods/whatever-you-want-to-call-them, for example? >> are they part of the type? or something else?) >> >> The point of duck typing is that you don't need to/you shouldn't document >> the 'types', seeing no purpose to restrict your definition of what's >> considered valid input. Surely if the object responds in all the ways you >> ask it to, it's fit for the task? >> >> Arlen > > > Arlen, > > Maybe I'm not in the correct mindset of dynamic programming. I've always > found it difficult to remember return values/parameter-types (i.e. classes) Which do you mean: types, or classes? :-) It's not just an abstract distinction. Here's an example. The ORM library ActiveRecord allows for its instances to have collections of other ActiveRecord objects. So you can do things like: teacher.students The object you get back identifies itself as an Array, when you ask for its class. However, its interface is only partially like that of a newly-minted Ruby array. In particular, #find is very differently engineered. So you really need to know how the object works, and the name of its class doesn't tell you. You need type information -- that is, information about what the object's actual capabilities and behaviors are. Of course it's possible (and people have done it) to decide up front that it's a bad practice to have objects that don't behave like newborn instances of their classes. But then you're fighting Ruby. The principle of extensible objects, and the principle of the separation of class from type (or "nature" from "nurture", in the object's life-cycle), is at the heart of Ruby. That doesn't mean you have to extend every object with a different module. But it does mean that you're limiting yourself a lot if you decide that there's something shady about objects that don't behave the way they did when they were born. David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for details and updates!