language? - How many of you know there are alternative JVM languages? - How many of you have heard/developed using Scala? - How many of you know what functional programming is?
languages, especially those that support functional programming - Did 'Functional Programming Principles in Scala' on Coursera in 2013 https://www.coursera.org/course/progfun - Currently working on a mixed Scala/Java project, which was previously a pure Java project
released publicly in 2004 - Initially designed for both JVM and .NET .NET support was dropped in 2012 - Part of the Typesafe stack, supported by Typesafe Inc. - Current Version: 2.11.1 - Free and Open Source http://scala-lang.org/
Java - Statically Typed - Multi-paradigm: Functional, Object-Oriented - Dynamic Languages Features eg. REPL, Lack of un-needed type annotation, Scripts
drop-in replacement for Java Mixed Java/Scala Project due to mixed compilation support - Not an 'all or nothing' preposition - Deployment-wise, it's just a JAR - Scala Code compiles to Java Bytecode - Can use existing Java libraries - Can use existing Java tooling (Ant, Maven, Gradle, JUnit) - Decent IDE support (IntelliJ, Eclipse)
_age: Int) { def age = _age // Getter for age def age_= (newAge: Int) { // Setter for age println("Changing age to: " + newAge) _age = newAge } } http://joelabrahamsson.com/learning-scala-part-nine-uniform-access/
as well as type parameters. Traits can have only type parameters. Abstract classes are fully interoperable with Java. You can call them from Java code without any wrappers. Traits are fully interoperable only if they do not contain any implementation code
a programming paradigm, a style of building the structure and elements of computer programs, that treats computation as the evaluation of mathematical functions and avoids state and mutable data.
It is possible to pass functions as arguments, to store them in variables, and to return them from other functions. - Lambda/Anonymous Functions - Closures - Higher Order Functions - Others: Nesting, Currying
library val plusOne = (x: Int) => x + 1 val nums = List(1, 2, 3) // maps take a function: Int => T nums.map(plusOne) // Inline anonymous nums.map(x => x + 1) // Even shorter form nums.map(_ + 1)
nums.exists(_ == 2) // => true nums.find(_ == 2) // => Some(2) // Reduce uses the first element of the input list as the initial accumulator value. nums.reduceLeft(_ + _) // => 10 // Fold takes an explicit initial value for the accumulator nums.foldLeft(100)(_ + _) // => 10
case 5 => "I am Five" case i: Int => "I am a Int" case s:String => "I am a String" case _ => "Unknown" } decipherType(5) decipherType(123) decipherType("hello") decipherType(false)
Concurrency - Scala actors were deprecated in 2.10 in favor of Akka Actors - Futures for parallel operations http://www.scala-lang.org/old/node/242 http://akka.io/
match Imperative vs Functional? - Scala is a better Java, proven for Production Applications. - Java 8 won't kill Scala. It validates the existence of Scala and will only make it more popular. - Learn Scala not just as a language, but learn it for its concepts