The Scala programming language celebrated its 10th anniversary last month while Java 8 is poised for its “final” release in March. Ironically, the two languages that competed for so many years are starting to look increasingly similar.
Java still tops the charts but Scala has gained new adherents due to its emphasis on functional programming. As Java 8 adds significant Scala features, there's a case to be made that Scala will diminish.
Though there's still plenty of reason to think Java 8 will obviate much of the reasons people turn to Scala, I recently sat down with Martin Odersky, the creator of the Scala language and chairman of Typesafe, to get his assessment of where things stand between two languages that share a love for the Java Virtual Machine.
Scala-Like Java Is Good For Scala
ReadWrite: Java 8 seems to have embraced some of the basic concepts behind your original design of Scala. Is that vindication? Or do you fear that Java 8’s enhancements might suck developers away from the Scala community?
Martin Odersky: Java 8 represents one of the most significant changes to the language in its history, with new constructs that will change the traditional ways Java developers have approached solving problems.
People often ask me if these features coming to Java will slow the adoption of Scala. Quite the opposite! Instead, I feel the acceptance of these features by the Java Community Process validates our innovation in language design on the JVM. As developers come to understand what these features are and how they work, they will also develop a better appreciation of the more extensive support of functional programming that Scala provides.
There is also likely going to be an increased interest to investigate Reactive tools such as Akka and Play Framework, even via the Java API.
Java 8’s Impact On Scala
RW: What will be the main impact of Java 8 on Scala?
MO: The list of features being included in Java 8 is actually quite long, but several of them are particularly interesting to me. Java 8 will definitely bring the Java and Scala developer communities closer together.
I also believe it will make life easier for polyglot language support on the JVM, while at the same time giving Java developers just a taste of how languages are evolving to support a higher degree of concurrency and parallelism.
Java Learns Some New Lambdas Tricks: Will Developers Follow Along?
RW: What features in Java 8 stand out for you?
MO: To me, the most interesting new feature is lambdas. It will be more helpful for Scala to be able to standardize the bytecode emitted by Scala’s compiler in the way Java implements its support of this feature, using Functional Interfaces.
I doubt this will be a difficult leap for most existing Java developers who are already familiar with anonymous implementations of interfaces, which Java has permitted for some time now. The same rules will apply, such as not being able to “close over” non-final external values.
Java 8’s implementation of lambdas will bring new methods to the java.util.stream.Stream type that will sound very familiar to Scala developers. In my experience, these methods make writing high-level collection code a lot easier and act as a “gateway drug” to change to a more functional style overall. Heavy users of these abstractions would then also appreciate the additional readability Scala bring to the table with itsfor expressions.
Having these implementations will also likely be very helpful for tools such as Akka and Play Framework in supporting a more cohesive Java API, allowing them to create Java-based functional interfaces where they could not before. This will mean the APIs will be very similar regardless of whether you’re calling them from Scala or Java, increasing usability for programmers in both languages.
Make Bytecode, Not War
RW: Any other features that stand out in Java 8?
MO: Scala developers will also be excited by Java 8’s inclusion of default implementations of methods in Java Interfaces. Scala compiler developers have long had to jump through hoops to create bytecode for Scala traits that would be acceptable to the JVM, such as creating an interface for the trait and a class for the implementation of methods that would be extended by classes extending that trait. Now the bytecode emitted by the Scala compiler can be cleaner and match the Java specification, while continuing to support linearization.
Java: A Little More Like Scala Every Day
RW: It sounds almost like you are in “embrace mode” with the Java community. I’m reminded of Sprint creator Rod Johnson's controversial ScalaDays keynote last summer in New York. Johnson listed examples of Scala being opaque and hardcore as obstacles to widespread adoption. He called for Scala to become more Java-like, more friendly and usable to the mainstream of developers.
MO: Rod is a good friend of Scala’s, actually! He sits on the board of Typesafe with me. And Typesafe is focused on providing first-class support for Java developers with the Akka concurrency toolkit and the Play Framework.
In fact, Typesafe believes that the addition of these new Java 8 language features will help us expose more powerful and fluid APIs for Java developers that closely mirror much of the way we code from Scala. This is the benefit of having Java introduce constructs similar to those in Scala. The introduction of these features, as well as other Scala-influenced features such as the purely non-blocking CompletableFuture and Parallel Collections, underscore the impact Scala’s success has had in influencing the future of Java.
Lead image by yukop on Flickr