Like it or not, closures are coming to Java

Closures should aid multicore development, but some still aren't happy about it

Project Lambda, a much-talked-about Java technology effort, is expected next year to bring closures capabilities and related features to Java that are promised to aid multicore programming. Java is the lone holdout among mainstream object-oriented languages in not having closures. Experts disagree, however, on just how valuable closures are for Java, and whether they're worth the effort for developers.

Also known as lambda expressions and anonymous methods, the support for closures "makes a number of programming practices cleaner and less error-prone," says Java founder James Gosling. But he cautioned that if misused, closures can "churn in the heap," dragging down performance in large applications. Still, Gosling likes the notion of closures: "I'm glad to see them finally arrive."

IDC analyst Al Hilwa also favors the adoption of closures in Java. "By sticking with a high-level description of computation, Lambda will allow the underlying engine to optimize and parallelize the computation to a much greater degree," which is what multicore apps need, he said.

Also giving a thumbs-up to closures is one-time Java developer and current PHP guru Andi Gutmans, CEO of Zend Technologies. "Closures are an important feature to have in the more modern framework." Gutmans says developers will retain the ability to code on the fly, but do so in a structured way.

But Shai Almog, CEO of mobile solutions vendor Codename One, says the addition of closures is not a good change for Java. Although closures reduce the amount of syntax required versus using inner classes or anonymous inner classes, "they do this at the price of code that is harder to parse, both for machine and the human being." When developers make a small syntax mistake, the IDE is less helpful since the number of syntax options grows significantly, Almog says. "Furthermore, although the code is arguably more readable, it is often less structured and modular as a result."

Closures capabilities had been left out of Java because of controversy over design, Gosling says. "Inner classes were a step down the road toward closures that was made up of the noncontroversial concepts.  But I always viewed it as unfinished."

Longtime Java developers might need some time to get used to using closures, whether or not they see the benefits that Gosling, Oracle, and others do.

This story, "Like it or not, closures are coming to Java," was originally published at InfoWorld.com. Get the first word on what the important tech news really means with the InfoWorld Tech Watch blog. For the latest developments in business technology news, follow InfoWorld.com on Twitter.

Copyright © 2012 IDG Communications, Inc.