Skip to main content

Poll Result: Most Consider Lambda Expressions in Java a Good Idea; Some Disagree

Posted by editor on June 12, 2012 at 9:58 AM PDT

The results of the latest completed poll indicate that, in general, developers consider the addition of Lambda Expressions (closures) to Java (which will happen in Java 8) to be a good idea. However, opinion is not universally in this direction. A total of 401 votes were cast in the poll. The exact question and results were:

Is adding Lambda Expressions (closures) to Java a good idea?

  • 48% (192 votes) - Of course! We've needed this for a long time!
  • 15% (59 votes) - Probably
  • 6% (25 votes) - Maybe
  • 2% (7 votes) - No, threads and the Fork/Join Framework are sufficient
  • 14% (55 votes) - No, because they'll be misapplied, complicating lots of code
  • 11% (43 votes) - I don't know
  • 5% (20 votes) - Other

First, my normal disclaimer: these are the results of a voluntary survey, not a scientific poll. Still, I think the results reasonably reflect the attitudes of Java developers. While about half of the voters think Lambda Expressions in Java have been long overdue, significant skepticism is also evident. Combining the "Probably," "Maybe," and "No" results yields 37% of developers expressing at least some doubt about whether adding closures to Java is a good idea.

Now, you can think adding a new feature to a language is a good idea even if you yourself are unlikely to use that feature frequently. But, to have doubts about whether adding a major new feature to a language is a good step -- that's an entirely different matter. In this poll, 14% actually believe the addition of Lambda Expressions will be, on balance, harmful, because some developers will apply the shiny, glitzy new capability in situations where there's no sensible reason for doing so.

Java Champion Kirk Pepperdine, a Java performance expert, has often stated that complex code can easily produce performance bottlenecks. For example, in this 2009 interview with Janice Heiss, Kirk states:

Brian Goetz and other influential developers have been saying for some time that if you write overly complex code, something's wrong.

I can cite example after example where the act of simplifying code allowed us to get the performance that we needed. Surprisingly enough, this principle actually goes beyond languages, so some of the biggest gains I've seen have been in applications where we simplified Smalltalk code.

In the Java language, it becomes doubly important because now we have runtime optimizations being applied to the code, and complex code confuses the optimizers. When you confuse the optimizers, they do not do a good job of optimizing, so you have a couple of problems with Java when you write complex code.

Kirk also highlights the need to measure performance, not just guess. The entire purpose of Lambda Expressions is to enhance performance on multicore devices. But, if you don't understand Amdahl's Law, you can easily waste lots of development time and effort writing overly complex code that either minimally improves performance, or even degrades overall performance. And, on top of it all, when the original developer leaves the company, successive developers who need to maintain or upgrade the code are faced with something that's basically unreadable, and readily susceptible to being broken by the tiniest modification.

This, I think, is the kind of thing that has many concerned about the Lambda Expressions enhancement that's coming in Java 8.

Still, what choice is there? The design of Java's Lambda Expressions will simplify the porting of legacy applications such that they can utilize multiple cores in modern devices. To not parallelize the key computational components in these applications will ultimately lead to their death due to horrid performance compared with competing apps written in other languages that support parallelism. It's the proverbial double-edged sword (something that "cuts both ways").

Lambda Expressions are a benefit (in the hands of excellent programmers), but also a liability (in the hands of less talented / less experienced developers). But, in my view, they are absolutely needed, because of the Multicore Challenge.

Opinions on closures in Java, circa 2006

Shortly after I posted this poll, my editorial predecessor and friend Chris Adamson tweeted about the fact that he ran an almost identical poll back in 2006! That poll asked "Would you like JDK 7 to support closures?" 41% said yes, 21% said no, 10% said they weren't sure, and 27% didn't know what a closure is. Again, while polls aren't scientific, I think this implies that even six years ago a lot of people had doubts about adding closures to Java.

More people today are in favor of having Lambda Expression support in Java. This makes sense given the explosion of multicore devices in the intervening years -- even down to quite small hand-held devices. And the multicore trend will likely accelerate in the coming years, rather than diminish, due to the already-in-progress demise of Moore's Law.

New poll: Java DB improvements/enhancements

Our new poll asks What new feature or improvement would you most like to see in Java DB?. Voting will be open until Friday, June 22. Weblogs

Since my last blog post, several people have posted new blogs:

Java News

Here are the stories we've recently featured in our Java news section:


Our latest Spotlight is Patrick Curran's time to get to work:

As I've previously reported in this blog, we planned three JSRs to improve the JCP

Related Topics >>