Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Scala

Introduction to Scala

Slides from a talk given at Brunel University and Enear in Portugal

Nigel Warren

March 19, 2014
Tweet

More Decks by Nigel Warren

Other Decks in Programming

Transcript

  1. Scala Introduction Proposition … Reuse - Java Libraries and runtime

    JVM Based Consise - Less Code that does more Parallel Ready - Builtin Support via Parallel Libs Expressive - Combines OO and FP Fewer Bugs - Static Inferred Type System
  2. A Little History Created by Prof Martin Odersky at EPFL

    Lausanne 1996-1997 - Pizza 1998-2000 - GJ, Java Generics, javac 2003-2006 - Scala as an academic ‘Experiment’ 2006-Now - Scala in production 2014 - Ten years of Scala
  3. Reuse Principle - Don’t reinvent underlying core abstractions and environment

    Use any underlying Java Library direct from Scala Scala can extend underlying Java types with new features Scala compiles to Java .class files and hence uses the JVM runtime environment (JIT)
  4. Java Virtual Machine Host Hardware Scala Class Files Java Class

    Files Scala Class Files Java Source Files Scala Source Files
  5. Rich Scala Libraries Collections - Implausibly powerful and productive collections

    for iterative and parallel operations Async - Future (impl Promise) based asynchronous model DSL - Internal and External Domain Specific Languages via Parser Combinators
  6. Consise Java … public class Person { public final String

    name; public final int age; Person(String name, int age) { this.name = name; this.age = age; } } Scala … case class Person(val name : String, val age : Int)
  7. Parallel Ready Exploits immutability to ‘automate’ parallel operations val movie

    : List[Image] = loadImages movie.map( img => img computeHash ) // and in parallel movie.par.map( img => img computeHash )
  8. Parallel Collections Split work by number of available processors On

    completion of tasks threads steal work from other queues
  9. Adoption Experience Reduction in Lines of Code (Counting problem) Aim

    to increase readability Works seamlessly* with Java Selectively Migrate project/libraries Common entry point is testing framework Programmer Joy <==> Programer Productivity The ‘well of confusion’ - idiom overload
  10. Fewer Bugs Use Types to drive out bugs at compile

    time. e.g. Options to exclude NullPointerExceptions Immutability and Pure functions Collapses concurrent update problems Easy to test Scala Test and Scala Check More time coding Less time in debugger
  11. Scala Libraries Akka - Actors and Distribution Tools Play /

    Spray - Web Framework (REST services) JSON and XML parsers Testing - ScalaTest and ScalaCheck TypeLevel - Shapeless, Spire, Scalaz, Scalaz-Stream
  12. Scala Research EPFL - Programming Methods Laboratory (LAMP) Type simplicity

    via dependent types - ‘Dotty’ ‘The Trouble with Types’ - InfoQ.com Stanford - Pervasive Parallel Lab (PPL) DSL based parallisation - “Delite” UC Berkeley - AMP Labs Spark, GraphX, ML Lib ( now Apache )