Wednesday, November 29, 2006

To Closure or Not

First, read this before continuing.

Both of the extreme cases seem comical. One takes the position of nothing but objects and the other nothing but blocks. It seems that pure object-oriented programming is at odds with functional programming. But, it's not. They need each other. I think Smalltalk and Ruby strike a good balance in this area. Blocks are used as lightweight objects (ala syntactically cheap) where a full object definition would be cumbersome. But, having nothing but blocks would also be problematic. For bigger things, we use full objects. It's the balance of having both that allows us to choose the one that allows us to more succinctly express our solution.

I don't know why people argue these things. There are problems that are better expressed in objects and others in closures (blocks). Why do I have to choose one over the other? I want both! There's also a lot that object-oriented programmers can learn from functional programmers and visa-versa. In fact, I'm always shocked how much functional programming is in pure object-oriented languages like Smalltalk and Ruby.

I'm going to go message something.

2 comments:

kerrin said...

(The link appears to be gone; Something weird going on with the UIUC Wiki).

Vassili's response was a seminal piece of work.

Some of the "get rid of blocks" effort came from Objective-C. The Objective-C guys never got around to adding anything block like. And one of the things that's interesting, is the patterns and techniques that have evolved to make up for the lack of blocks. One is the "higher order messaging" work that Marcel Weiher has done, which Michaell Lucas Smith later replicated in Smalltalk. To be sure, it's just better/easier to have blocks. But there's some interesting stuff that actually comes from the "how would we do it without blocks" approach.

Ruby blocks aren't as blocky as Smalltalk blocks either. :)

kerrin said...

Above comment from Travis Griggs, who is Kerrin's husband. :) I hate these "register to comment" blogthings.

Amazon