From: Rick DeNatale Date: 2009-07-15T01:21:26+09:00 Subject: Re: Twelve rules of Ruby On Tue, Jul 14, 2009 at 11:46 AM, David A. Black wrote: > Hi -- > > On Wed, 15 Jul 2009, Marc Heiler wrote: > >>> Objects don't "have" methods >> >> Hey David, you gotta tell this Dave Thomas so that he can talk about >> this in new pickaxes too. I sort of stopped learning after reading >> pickaxe, because this concept still surprises me ... :> > > That's what keeps it interesting, isn't it? :-) > > I certainly use the "have" terminology informally. But it's important > to understand that "obj has a 'talk' method" is really shorthand for: > "obj can successfully resolve the message 'talk' because there is a > 'talk' method definition in one of the classes or modules in its > method lookup path." The wordier version will enable you, for example, > to understand super, inheritance, include, extend, the difference > between undef_method and remove_method, and various other things... > whereas "has", while a handy shorthand, doesn't pan out as a real > description of the object model. I know what you are driving at, but there are some things about your statement of that rule which bother me. First of all, as you just stated, object DO in a sense have methods, in the same sense I have, say, an iPhone, because I know how to find it, usually. And the idea that "they have the intelligence to resolve messages by looking for methods along their class/module lookup path" is a bit of a pedagogical lie. If an object has any intelligence that intelligence is held in its methods, and state. Objects don't really know how to find their methods, it's the implementation of the language whether you call that an interpreter, or a virtual machine, which knows how to do that. How best to think about such things depends on where you are on the journey of learning. A certain perspective can get a learner over a hump, even it it's not exactly correct. But it can also lead to the stuff you and I were tweeting about a few days ago, when I discovered that there are adults in this world who firmly believe that Two Thousand and One, means 2000.1 because their fourth or fifth grade minds were taught that "and means decimal point," and never realized that this was a shortcut way of telling them that when they see a . in a digit string, it means decimal point and they should say "and" and then the following decimal fraction. At one level, the important thing is to be able to reason about how methods are found based on the reference implementation of chained classes and model proxies in MRI. On the other hand, this approach is actually talking about a shadow of the implementation displayed on the walls of Plato's cave. There are certainly conceivable Ruby implementations which used a more Self, or JavaScript like object model, in which methods were more closely associated with instances, but still acted AS IF they had the MRI implementation for all outside observers. In my years dealing with language standards, I've learned the power of that explicit 'AS IF' to separate intent from implementation. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale