scala past, present & future
TRANSCRIPT
Scala PasT, Present &
Future @mircodotta
Who am I?• Felt in love with Scala in 2005
• Open Source contributor: Scala compiler & IDE, Lagom, Play, etc.
• Recently co-founded a Scala tooling company!
• Available for trainings (Akka/Play/Scala/Spark) and consulting.
Whoever wishes to foresee the future must
consult the past Macchiavelli
Scala: The Past
• Scala first release in 2003
• But, what’s the story before Scala?
Pizza
• 1995-19981
• Superset of Java with generics, first-class functions, case classes and patter matching.
• Why the name?
• Java was hacker’s drink
• Hacker’s food was needed ;-)1. www.slideshare.net/Odersky/scala-evolution/3-Pre_History1980s_Modula2_Oberon199095_Functional
Java 1.5
• Pizza led to Martin Odersky working on the Java compiler (javac).
• Martin co-designed the first version of generics in Java, and has written the recent javac.
Scala origins
• Goal: unify object-oriented and functional paradigms.
• Java was too constraining, hence the motivation to start fresh.
2003
Scala Martin’s mantra
• A language with a small core, few constructs but high abstraction power.
• Fact: Scala has less keywords than Java!
Scala evolution
First release
2003
Twitter adoption
Scala 2.0released
2006
Akkafirst release
2009
Lightbend(formerly Typesafe)
commercialsupport
Scala 2.9released
&Scala project
movedto GitHub
2011
Scala evolution
2012
Scala 2.10released
Scala Actordeprecated
and replacedby Akka
2013
Scala.JSreleased
2014
Scala 2.11released
2016
Scala 2.12(currently RC2)
Scala CentreFoundation
created!
Scala 2.9 to 2.11
• Releases are mainly about stability.
• Only new features:
• Value classes
• Implicit classes
• String interpolation
• macros (experimental)
Scala 2.12
• No additions to the language.
• So… ?
Scala 2.12• Scala 2.12 requires Java8.
• trait compiled to Java8 interface.
• Binary compat & reduced bytecode!
• scalac λ bytecode mimics javac’s.
• scala.FunctionN compiles to SAM type (Java8 λ).
• New backend & optimiser11. https://dl.dropboxusercontent.com/u/4881107/website/scala-user-group-2016.pdf
New trait encoding
trait PriceAlgorithm[Item] { def apply(item: Item): Double = ??? }
Let’s compare Scala 2.11 vs 2.12 bytecode
trait PriceAlgorithm[Item] { def apply(item: Item): Double = ??? }
Compiled with Scala 2.11
interface PriceAlgorithm<Item> { abstract double apply(Item); }
abstract class PriceAlgorithm$class { static double apply(PriceAlgorithm, java.lang.Object);
static void $init$(PriceAlgorithm); }
Two classfiles
trait PriceAlgorithm[Item] { def apply(item: Item): Double = ??? }
Compiled with Scala 2.12
interface PriceAlgorithm<Item> { public double apply(Item);
static double apply$(PriceAlgorithm, java.lang.Object);
static void $init$(PriceAlgorithm); }
Only one classfile!
Java8 API from Scala
Scala λ assignable to Java 8 λ
scala> import java.util.stream.{Stream, IntStream} scala> import java.util.{Arrays, List}
scala> val myList = Arrays.asList("a1", "a2", "b1", "c2", "c1") myList: java.util.List[String] = [a1, a2, b1, c2, c1]
scala> myList.stream. filter(_.startsWith("c")). map(_.toUpperCase). sorted. forEach(println) C1 C2
Why an optimiser?
• Some well-known patterns are not optimised by HotSpot (Oracle JIT).
• Transform the code to please HotSpot.
• Inlining vs binary resilience.
• Optimiser is not a magic wand, but rather a tool for experts.
• Compile with the -optimise flag.
Scala future
2016
Scala 2.12 Scala 2.13 (Aida)Improve the
library!Smaller core & stabilise
Q1 2018
(Don Giovanni)Faster compilerImprove binary
compatibility (TASTY)
2020?
Dotty?
• Dotty is the new Scala compiler Martin is working on with his group at EPFL.
• It’s research work, but a first release should be available soon.
• https://github.com/lampepfl/dotty
• Goal is to simplify the language.
The future of Scala
on a A4 paper
Credit goes to @malweene
https://twitter.com/malweene/status/743117270948274176
Questions?
@mircodotta