Tuesday Jul 22, 2014

Lift Yourself Up with Functional Thinking

Yippee! Java SE 8 has Lambdas and Streams, but what does that mean? Are you now automatically a functional programmer? Learning the syntax of a new language is easy, but learning to think under a different paradigm is difficult. That's where Neal Ford's "Functional Thinking" OSCON session is helpful. Ford is an architect, author and "meme wranger" for ThoughtWorks.

Book Cover
Ford started with the story of the lumberjack who was very good at using an axe. Someone recommended he try a chainsaw because it was so much better. He took the chainsaw, and bashed it against the tree, and concluded he should stick with the axe. The story is apt on so many levels, but especially: the danger of trying the same old thing with new tools. Ford said programmers learn the syntax and concepts of a language at the same time, and they get tend to get the two entwined in their minds. So, becoming a functional programmer is not so much learning new syntax, but thinking about problems and their solutions differently. Ford explained that as a functional programmer, you need to focus on results, not steps.  

How is Functional Programming different than imperative programming? FP is a cleaner, more effective way to solve problems. FP has you working at a higher level, it makes you more productive, and it has you thinking at the problem level. With FP, the problem solution reads like the problem statement. Teasing apart the parts of a problem also makes it easier to parallelize your code. With FP, you can lift yourself up, think more abstractly about your programming. Also, you can let the runtime handle the busy work of memory allocation ("Life's too short for malloc!" Ford exclaimed), garbage collection and variable state. You'll be more productive.

Functional Programming is more a way of thinking than a toolset. Get your thinking on with these resources:
Functional Thinking Book
Functional Thinking Videos

Thursday Aug 15, 2013

Trying Out Lambda Expressions in the Eclipse IDE

A new article, now up on otn/java, by Deepak Vohra, titled “Trying Out Lambda Expressions in the Eclipse IDE,” demonstrates how to take advantage of lambda expressions in Java SE 8 using the Eclipse IDE and virtual extension methods.

Vohra begins with the basics:
“Lambda expressions, also called closures, are a short-form replacement for anonymous classes. Lambda expressions simplify the use of interfaces that declare a single abstract method, which are also called functional interfaces. In Java SE 7, a single method interface can be implemented with one of the following options.
* Create a class that implements the interface.
* Create an anonymous class.”

Vohra explains that while lambda expressions can be used to implement a functional interface without creating a class or an anonymous class, they can be used only with interfaces that declare a single method.

Benefits of lambda expressions include:
* Concise syntax
* Method references and constructor references
* Reduced runtime overhead compared to anonymous classes

Vohra gets under the hood to explain the basics of lambda syntax, along with the nature of functional interfaces and target types, offering copious examples. All in all, the article offers a first-rate primer on how to make use of lambda expressions and virtual extension methods using the Eclipse IDE.

Check out the story here.


Insider News from the Java Team at Oracle!



« June 2016