jump to navigation

Ola Bini’s Ducktator and Controversial Topics
Thursday, 21 September 2006

Posted by austin in: Ruby, trackback

UPDATE September 21: Yesterday, I got a little annoyed at Ola Bini and something he said. He was surprised by the reaction he got to his use of a term which is very common in Ruby parlance, but has overloaded meanings. At some point in the mailing-list discussion, he stepped away and made what some (myself included) felt was a sideswiping response at the participants of the on-list discussion. We have resolved the conflict and clarified our positions toward each other, and rather than pretending that the whole episode didn’t happen, he and I have agreed to edit our respective blog posts so that they are far more explanatory and less inflammatory overall. Ola certainly didn’t mean any harm by his post, and I believe him. As such, the title of this post has changed. I’m sure that for a while at least, you’ll be able to find the originals in the Google Cache, or maybe the Wayback machine, but understand this: what is below and on Ola’s updated post reflects how things are.

After releasing Ducktator, Ola Bini was surprised at the responses that were received toward his use of the term “duck typing.” The discussion went on for a while, and Ola eventually decided to make a post to his blog about it. I think that the library is cutely named (as others on the ruby-talk mailing list, I like puns) and several people have suggested that it’s going to be very useful for them. However, I don’t think that Ducktator is about duck typing, and its name is unfortunate in that sense, because it has the chance of confusing the discussion surrounding duck typing even further.

What is Duck Typing?

The simplistic answer to this, of course is, “if it walks like a duck, and
it quacks like a duck, then it must be a duck.” This is certainly true, but the
real question is more “how do I know if I’m duck typing?” Many people, myself
included, consider duck typing a matter of trusting one’s callers and
documenting your API well enough to ensure that the callers can trust that you
won’t do something they’re not expecting. The canonical example of this is a
logger.

class SimpleLogger
  def initialize(recipient = nil)
	@out = recipient || $stderr
  end

  def log(message)
	@out << "#{message}\n"
  end

  attr_reader :out
end

l = SimpleLogger.new([])
l.log "Hello"

SimpleLogger simply trusts its users to give it recipient classes that respond to #<<. Now, this is a simple case, but what about something a little more complex? Well, Text::Format can accept a hyphenator object, which must implement a particular method that has a particular arity. So when you assign a hyphenator object, Text::Format does object signature validation for both the presence of the #hyphenate method and its arity (two, I believe). I consider Text::Format’s approach less duck-typed (possibly even not duck-typed, although it is more dynamic than class-based validation) than I consider the SimpleLogger class above. Both are useful techniques, but to Text::Format is less flexible than SimpleLogger.

That’s OK, though. The increased complexity of the API for hyphenation suggests that validation is not a bad thing. When you get into the realms of problems that Ola wrote Ducktator for, you need even more complex — and arguably less flexible — validation. As I said yesterday:

As Eric Mahurin noted in a spin-off post from the main thread about Ducktator, there’s a number of possible definitions for duck typing, so it’s understandable that people find themselves confused. I’m not Dave Thomas (he and Andy applied the term first to Ruby, as far as I can tell), but as far as I’m concerned, object signature validation is not duck typing. It never has been, and it never will be. It’s object signature validation.

I don’t care whether you do object signature validation by the class of the object (in which case you’d usually be unnecessarily restricting yourself in Ruby) or by the actual method or methods you need, you’re still not doing duck typing.

I still believe this to be true. By all means, use Ducktator if it’s going to help you. It isn’t what I consider to be duck-typing, though.

Comments

1. bystr – Wednesday, 20 September 2006

Thank you very much, Austin!!! I do not always like your discussion style, however this time you expressed precisely what has been boiling in me regarding all this issue and the final Ola’s post.

2. pldms – Thursday, 21 September 2006

I’m not the most attentive reader, so I seemed to have missed the ‘name calling’.

As it happens I thought Ola was overreacting, having just wandered into a terminological minefield which he didn’t anticipate (something many of the replies failed to clarify). However this post seems to justify some of what he said. I hope this post is an abberation in the ruby community. Play nice :-)

3. austin – Thursday, 21 September 2006

Obviously, I disagree, pldms. I’m not religious about Ruby in the least. What I am is justifiably angry that Ola didn’t feel that he could continue what was a good discussion and instead posted a polemic with numerous exaggerations and untruths.

I pointed out all of the name-calling in my post here; I don’t appreciate being told that I obviously don’t understand a technical matter when (1) that matter never came up, (2) I in fact do understand the technical matter at least as well as Ola did. Ola’s response was, to borrow a phrase from M*A*S*H, horse hockey. It was arrogant and dismissive of anyone who disagreed with him. It was a zealot’s argument.

4. pldms – Thursday, 21 September 2006

On reflection I suppose I understand ‘name calling’ in the sense of personal attacks, so maybe that explains my confusion.

However I did go back and re-read Ola’s messages and … well … I just don’t hear the arrogance etc that clearly you do. He mentions duck typing, in the way I remember from the pick axe book, and, well, an exchange of opinions ensues. Matz seems to agree this is a reasonable interpretation of the term, and he knows more than I.

Ola’s blog post contains some hyperbole, but it isn’t nasty by any stretch of the imagination. There is a worry that a community can get dogmatic, set in its ways. Happens to the best of us.

I read a minor slight from a concerned developer, you read an unpleasant attack from a zealot. For all I know you could be right; maybe my principle of charity is acting up. But Ola seems like a good guy generally.

5. austin – Thursday, 21 September 2006

Please note that the above comments refer to an earlier version of this article under an entirely different title. I am not disowning my previous post; at the time with the understanding I had of what had been said, I believe that I was correct to say what I said, if too harsh. However, as I note above, Ola has clarified his original post, so I have modified and renamed my post to discuss the issues raised by the wider discussion.