Now Playing Tracks

Why Lambdas Suck by Jamie Allen (Typesafe)

There is a lot of focus on the upcoming release of Java8 with lambda support.  And the fact that Oracle will make functions first-class citizens in the Java ecosystem is very exciting.  However, lambdas are not magic awesome-sauce that you spread across your Java application and everything will just be wonderful from that point forward.

Lambdas come with considerable overhead, from several perspectives.  The anonymous nature of lambdas means that exceptions that occur within their bodies have stack traces that can be very difficult to decipher.  The way that most developers tend to write lambdas, where they attempt to be as concise as possible and keep all of the code on one line, means they frequently cannot be debugged with an IDE - you can’t step into code, for example.  Lambdas also cause issues with polymorphic dispatch on the JVM, and don’t even get me started about the issues with closing over mutable state!

Understand that I am not against functional programming.  I wholeheartedly believe that the core tenets of functional programming, including immutability, referential transparency and functions being first-class citizens are invaluable for writing “correct” code.  However, having lambdas has nothing to do with functional programming per se - it’s merely one mechanism through which we can apply functions.  And I believe there is a better way to use functions than by using lambdas.

In my talk at JAXConf 2013, I will be reviewing this and a whole lot more, providing Java and Scala developers with best practices for how to survive in a lambda-based programming model.  Join me in June in Santa Clara!

Jamie Allen -Typesafe
Jamie Allen is a consultant for Typesafe with over 19 years of experience delivering enterprise solutions across myriad industries, platforms, environments and languages. He has been developing enterprise applications with Scala since 2009, primarily using Actors for fault tolerance and managing concurrency at scale.
 
image
To Tumblr, Love Pixel Union