Friday, December 18, 2009

Does Java Need an 'Extract Closure' Refactoring?

A straw-man writeup has been proposed by Mark Reinhold for including Lambda expressions (or Closures) in Java 7.

Over the course of my career as a developer I have never used a language where closures were a tool in the developers' toolbox. Because of this my brain does not create solutions using closures. Since my conversion to Test Driven Development I work hard to ensure that I am implementing the simplest solution possible for the feature that I am developing. For this reason I have titled this post "Does Java Need an 'Extract Closure' Refactoring?" rather than something more obvious, such as "Does Java Need Closures?"

I won't write any code using closures because a closure isn't the simplest thing that can work. I know this because of the millions of bits of code that I have already written in Java without closures.

The only way I can envision myself using a closure would be as the result of a refactoring. For me to extract code into a closure it will have to make the code easier to read and/or improve the reusability of the code.

I'd really like to hear from developers with hard core experience using closures. Please reply to this post with your thoughts.