Hi --

On Thu, 29 May 2008, Mark Wilden wrote:

> On May 28, 2008, at 8:59 PM, Avdi Grimm wrote:
>
>> On Wed, May 28, 2008 at 6:23 PM, Mark Wilden <mark / mwilden.com> wrote:
>>> Well, the desired goal is in fact to recognize objects that are numeric. 
>>> One
>>> of the purposes of classes in OOP is to categorize things.
>> 
>> Not really, no.  That reflects an attitude that has more to do with
>> C++ or Java than with OOP.
>
> I must respectfully disagree. I learned OOP (in 1989) before C++ was even 
> hardly available on PCs, much less Java. The OOP language I learned was an 
> amalgam of Smalltalk and Lisp. I cut my teeth on Bertrand Meyer, Adele 
> Goldbert, Brad Cox, and Grady Booch. I can say quite categorically, that in 
> OOP, classes are ways to generalize. You generalize based on characteristics 
> and behaviors. A class is not simply a random collection of methods. It would 
> be rather useless if class was unrelated to category.
>
> But I'm finding these remarks about "attititude" kind of amusing. It's like 
> Ruby isn't a tool, it's a "mindset." We don't forgo something like Numeric 
> === v because it's _wrong_ (the OP in fact said it was slightly more 
> readable), but because Ruby has duck-typing, and why use Ruby if you can't 
> duck type? I hope I'm not the only person to see how totally back-asswords 
> this kind of argument is.

Dave Thomas, who coined the term "duck typing", has described it as
"a way of thinking about programming in Ruby." So it is, in that
sense, a matter of attitude. The term has been beaten and battered
over the years to the point of unrecognizability, but it's pretty
simple in its original form.

Duck typing, as a way of thinking, meshes nicely with Ruby, as a tool,
because of how Ruby objects are engineered: the *only* thing that you
can measure with certainty is what an object does when you send it a
message. You can ask it what its class is, what its ancestors are,
what methods it responds to, and so forth... but in the end, you hit
the singularity: the sending of the message. At that moment, whatever
is going to happen will happen.

The idea of duck typing, as I understand it, is to embrace this
inalterable fact about Ruby objects, rather than try to wish it away,
with ancestry checks and the like. This makes sense to me; it stands
to reason that a language with objects whose types can change during
runtime would be well-served by a programming style that deals as
directly and economically as possible with precisely that condition.


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 23-26           London (Skills Matter)
See http://www.rubypal.com for details and updates!