Heron-Centric: Ruminations of a Language Designer Closures and Anonymous Functions by Christopher Diggins August 22, 2006
There is a debate raging at the Lambda-the-Ultimate.com site about closures in Java. Here's my two cents on the subject.
The debate at http://lambda-the-ultimate.org/node/1684 is essentially whether closures are needed in Java or not. I have an issue with the debate: a lot of people are arguing for anonymous function, not closures.
A closure isn't neccessarily anonymous.
An anonymous function doesn't neccessarily capture the lexicial environment
While I completely agree that anonymous functions are very useful for certain styles of programming, closures have a very clear downside: they increase code coupling. Passing a single closure can extend the lifetime of massive numbers of objects, leading to a huge performance hit.
Closures are a very powerful feature, but dangerously so. They are arguably too easily abused. A language designer has the responsibility to force a programmer to be explicit about dangerous things.
I am not saying that there is any single right answer for all cases, but I do think that people need to make a clear case why closures are important to have versus anonymous functions.
Have an opinion?
Readers have already posted
about this weblog entry. Why not
If you'd like to be notified whenever Christopher Diggins adds a new entry to his weblog, subscribe to his RSS feed.
Christopher Diggins is a software developer and freelance writer. Christopher loves programming, but is eternally frustrated by the shortcomings of modern programming languages. As would any reasonable person in his shoes, he decided to quit his day job to write his own ( www.heron-language.com ). Christopher is the co-author of the C++ Cookbook from O'Reilly. Christopher can be reached through his home page at www.cdiggins.com.