• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is Java8's functional programming as good as in other languages?  RSS feed

 
Jane Jukowsky
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example, what can Ruby and Scala do that Java 8 can not, as far as functional programming goes?
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simplest response is that support for functional programming is "bolted-on" in Java 8, but "built-in" with Scala.

Unlike Java, Scala has been deliberately designed to support FP (as well as OOP), and this is reflected in its syntax, data structures and libraries. Many of these design decisions are relatively minor in themselves or also available in Java 8 (e.g. immutability by default, elimination of Java kruft, functions as first-class objects, powerfully functional collections etc), but when you put them together they make it much easier and more natural to program in a functional style using Scala than with Java. Here is a quick Scala tutorial for Java Programmers and Twitter's Scala School is a good place to get started with Scala.

Of course, there are other FP options on the JVM e.g. Clojure (based on Lisp), which is more of a purely functional language than Scala. However, right now, Scala seems to be gaining the most interest commercially, perhaps because people think it will be easier to make the transition from Java into Scala than into Clojure. You can write Scala like a "better Java", or go for a pure FP approach, because the language supports both approaches. Not everybody sees this as a good thing, of course!

IMO, if you really want to write code using functional programming on the JVM, the only reason to use Java 8 is if you have to work in specifically Java environment. Otherwise you're much better off choosing a language that is actually designed for FP.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!