Posts Tagged ‘Closures’

Review of Neil Gafters’ talk

March 24th, 2008 makii Comments off

Yes, it’s a little late, but so what?

About two weeks I visited a quite interesting talk by Dr. Neil Gafter, developer of Google Calendar, whom, in his spare time, proposes new language features for the Java Programming Language and Sun’s javac-Java compiler. The latest proposes BGGA closures, in conjunction with other nice features like control abstraction, function types and lots of other pretty useful things,is under heavy discussion.

At first I was unsure what to think about closures, lots of people compained about the syntax, and that noone ever will understand the code when here are some function types in it. But, honestly, can it get any more confusing than with generics? NEVER!!. During the talk I recognized the pattern, which clearly is derived from the code blocks I used to love in Smalltalk. Clearly there are some slight differences taking into account that Java is, contrary to Smalltalk, a strongly typed language.

Further than that, it gets really nice when using closures in conjunction with control abstraction: Often used example, which actually doesn’t make sense, as Java5 has a foreach loop built in, but let’s just say someone wants to implement a method like foreach, taking as parameter any type of Collection<T>, as well as a block of code, which itself takes as parameter one item of T. This method then can be imported statically by any class which has need of this particular foreach loop. This abstract functionality is, right now, hard-wired in the java compiler to the Java Collections framework from the runtime environment. *hick* Yes, exactly the way around it should NOT be.

Closures in conjunction with control abstraction have the power to enable APIs to implement their own control statements like, for example, a foreach-loop for Collections or Maps, performance logging, cleanup work, whatever you can imagine. Despite my reservations in the beginning, I can’t wait to see the BGGA proposal into Java7 or Java8. Hopefully we will see it!

Categories: Java, Technology Tags: , ,