Musings & Rambles , Introspections & Retrospections , Add-ons' & Plugins'

Monday, December 31, 2007

Closures in Java - What lies beneath ??

I was listening to the "Closures for Java" tech talk by Neil Gafter. The presentation was very impressive and the content was equally good. Yet,one basic question remains unanswered. Do we need closures in java at all ??

I have nothing against closures or it being added to Java. But i like to raise few debatable points:

1) Closures is not something new. According to Wiki:
The concept of closures was developed in the 60’s and was first fully implemented as a language feature in the programming language Scheme

It is an integral part of many functional programming languages. But the recent addition of closures to Java signals the functional + OOP convergence which i think is nice to have , but not necessary. Anything we can do by adding closures can be done without using closures. So there should be some really strong use cases to justify why a developer should choose closure over his routine coding pattern.

2) Java has Anonymous Inner Classes. But how many of the developers end up using this in their day to day job ? Closures, as i understand provides a lot of features which we can't do with the current day Anonymous classes. But the question is why can't we enhance the anonymous inner class itself to provide all the missing functionality ?Why go for a concept which requires its own grammar and semantics ?

3) Java is Turing complete language. I agree, this doesn't justify closures shouldn't be added, however, Java is complete in its own OOP way. Java was not built to be a functional programming language. If closures are required, why cant we just use a JVM compatible FP to provide that feature ?

These were some of the basic questions that came to my mind once i heard about closures. Will post the answers once i find :). In the meanwhile, if there are any closure enlightened souls, please enlighten me as well.

And by the way, Wishing others & myself a very happy new year - 2008 :).

No comments: