Effectively final

Rémi Forax forax at univ-mlv.fr
Mon Aug 15 14:04:16 PDT 2011

On 08/15/2011 04:41 PM, Tim Fox wrote:
> Actually I am really disappointed by this. If these kinds (I.e.
> closure/CPS style programming frameworks) of frameworks take off in the
> JVM world, Java is going to be the ugly kid on the block for programming
> in them. No such problem with Ruby, JavaScript, Groovy, Clojure,
> Scala.... As a long time Java programmer, I think it's a real shame that
> Java the language fails to modernise at the rate required to remain
> relevant. Love the JVM though:)

I don't know for Scala but all the other languages you cite introduce
capture of local variables because Lisp have it.
Lisp was not created with multi-core in mind :)

If you want to capture local variables, you have to at least:
  - introduce a pass by address semantics to Java,
    something which is alien to Java and that will require VM+JIT supports.

- find a non stupid semantics for algorithms that are inherently non serial
   int sum = 0;
   parallelArray.forEach( #{ it -> sum+= it; });

- invent a new semantics for a volatile local variable and
   a way to express compare and swap on it

- figure out how to serialize such beast
   (Java lambdas need to work in a Hadoop like environment)

And all of these for a corner case (see [1])

> Just my 2c of course.

So I think it's better to disappoint some people and educate everyone to 
use reduce:
int sum = parallelArray.reduce( 0, #{ element, sum -> sum + element });

my 2c too.

[1] http://www.artima.com/intv/closures2.html

More information about the lambda-dev mailing list