Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

Like this? Share it with your network

Share

soft-shake.ch - The feel of Scala

  • 1,709 views
Uploaded on

Mario Fusco...

Mario Fusco

The presentation is an introduction to the Scala language. It will show the most important characteristics and winning points of the language with special attention to some specific features like: the ability to painlessly mix functional and object oriented programming, its powerful collections framework, its type inference mechanism, the clear distinction between mutable and immutable data and how its actor model could make the concurrent programming more effective and less error-prone.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,709
On Slideshare
1,709
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
30
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. 2010 The feel of Scala Mario Fusco X6
  • 2. Programme de la Conférence www.soft-shake.ch Agilité iPhone Java Incubateur 8:15 Accueil des participants 8:40 Mot des organisateurs & Criée des orateurs 9:00 Keynote de Nicolas Martignole (30 minutes) 9:40 - A1 - - I1- - J1 - - X1 - Le terrain Agile Hello iPhone NOSQL also means RDF stores: an Le développement durable Android case study 10:40 Jean-Philippe Vigniel Stephane Tavera Fabrizio Giudci Dominic Williams 11:00 - A2 - - I2 - - J2 - - X2 - Integration of User Centered Design Développement d'une application La Tequila du développement Web Cloud Computing: anatomie et in Agile Development of RIA iPhone pilotée par les tests pratique 12:00 J. Borkenhagen, J. Desmazières Emmanuel Etasse, Van-Charles Tran Nicolas Martignole Marc-Elian Bégin 12:20 - A3 - - I3 - - J3 - - X3 - Adoption de l'Agilité par les usages Distribution d'applications iPhone Vaadin - Rich Web Applications in Les DVCS sont vos amis en Entreprise: Réalisation d'un Server-side Java without Plug-ins or Xavier Warzee AppStore interne JavaScript Sébastien Douche 13:20 Géraud de Laval Joonas Lehtinen Pause repas (50 minutes) 14h10 Keynote de Regis Medina (30 minutes) 14h50 - A4 - - I4 - - J4 - - X4 - Scrum, introduction et mise en Agile iOS Development JAX-RS and Java EE 6 IT Design & Ergonomy oeuvre avec iceScrum 15h50 Claude Aubry Jérôme Layat, Alexander Osterwalder Paul Sandoz Pascal Petit, Aude Lussigny 16h10 - A5 - - I5 - - J5 - - X5 - Agilité : 10 ans déjà Optimizing iOS applications Ecrivez et automatisez vos tests NoSQL : Enfin de la biodiversité fonctionnels avec jBehave dans l'écosystème des BD 17h10 Thierry Cros Marc-Antoine Scheurer Xavier Bourguignon Olivier Mallassi 17h30 - A6 - - I6 - - J6 - - X6 - Lean engineering iPhone et Agile, l'amour vache Let's make this test suite run faster The feel of Scala 18h30 Jean-Christophe Dubail Guillaume Duquesnay David Gageot Mario Fusco Mot de la fin & tombola
  • 3. The Feel of by Mario Fusco mario.fusco@gmail.com Twitter: @mariofusco
  • 4. Mario Fusco mario.fusco@gmail.com Twitter: @mariofusco lambdaj.googlecode.com
  • 5. Do we need a new language? Keep It Simple Vs. Do More With Less
  • 6. statically typed object-oriented functional scriptable Why Scala? concise Java compatible extensible concurrent
  • 7. Functions and Closures val isPositive = (x: Int) => x > 0 val numbers = List(-10, 5, 3, -2, 0, 1) val positiveNumber = numbers.filter(isPostive) val positiveNumber = numbers.filter(x => x > 0) val positiveNumber = numbers.filter(_ > 0)
  • 8. Scala Collections val animals = List(“dog”, “cat”, “horse”, “rabbit”) val romanNumbers = Map(1 -> “I”, 2 -> “II”, 3 -> “III”) animals.foreach(s => println(s)) animals.foreach(println _) animals.foreach(println) animals.map(s => s + “s”) animals.mkString(“, “) animals.count(s => s.length > 3) animals.remove(s => s.length > 3) animals.sort((s,t) => s.charAt(1) < t.charAt(1))
  • 9. Tuples val pair = (2, “items”) println(pair._1) // prints 2 println(pair._2) // prints items
  • 10. Clear distinction between mutable and immutable data val msg = “Hello,world!” // constant var value = 3 // variable scala.collection scala.collection.immutable scala.collection.mutable
  • 11. Named and default parameters class Person(name: String = "Goofy", age: Int = 30, location: String = "Milano") Person(name = "Mario", age = 36, location = "Lugano") Person(age = 36, location = "Lugano", name = "Mario") Person(age = 36, name = "Mario") Person(age = 36) Person()
  • 12. Operator overloading class Rational (n: Int, d: Int) { def this(n: Int) = this(n, 1) def + (that: Rational): Rational = new Rational(n * that.d + that.n * d, d * that.d) def + (i: Int): Rational = new Rational(n + i * d, d) }
  • 13. Implicit conversion val a = new Rational(2, 3) val b = a + 2 // = 8/3 val c = 2 + a // Compilation Error implicit def intToRational(x: Int) = new Rational(x) Val c = 2 + a // = 8/3
  • 14. Tony Hoare, who invented the null reference in 1965 while working on an object oriented language called ALGOL W, called its invention his “billion dollar mistake” Options val capitals = Map("Italy" -> "Rome", "Switzerland" -> "Bern", "Germany" -> "Berlin" , "France" -> "Paris") println(capitals.get("Italy")) // Some(Rome) println(capitals.get("Spain")) // None println(capitals.get("Italy").get) // Rome println(capitals.get("Spain").get) // thorws Exception println(capitals.get("Spain").getOrElse("Unknown")) // Unknown
  • 15. Traits class Animal { def eat(): Unit } trait Mammal extends Animal { def giveBirth(): Mammal } trait HasWings extends Animal { def fly(): Unit } trait HasLegs extends Animal { def walk(): Unit } class Snake extends Animal class Frog extends Animal with HasLegs class Cat extends Animal with Mammal with HasLegs class Bat extends Animal with Mammal with HasWings class Chimera extends Animal with Mammal with HasWings with HasLegs
  • 16. Case classes trait Expr case class Var(name: String) extends Expr case class Number(num: Double) extends Expr case class Unop(op: String, arg: Expr) extends Expr case class Binop(op: String, l: Expr, r: Expr) extends Expr
  • 17. Pattern matching def simplify(expr: Expr): Expr = expr match { case Unop("-", Unop("-", e)) => e // Double negation case Binop("+", e, Number(0)) => e // Adding zero case Binop("*", e, Number(1)) => e // Multiplying by one case _ => expr } // Simplify double negation: simplified = Var("x") val simplified = simplify(Unop("-", Unop("-", Var("x"))))
  • 18. Duck typing is the dynamic mechanism that allows to discover a dog cannot say quack only at runtime ... in production ... on friday evening Structural Typing (duck typing done right) doQuack(d) { d.quack() } def doQuack(d:{ def quack():Unit }) = class Duck { d.quack() quack() { println "quack" } } class Duck { doQuack(new Duck) def quack() = println "quack" } class Dog { doQuack(new Duck) barf() { println "barf" } } class Dog { doQuack(new Dog) def barf() = println "barf" } doQuack(new Dog) compilation runtime error error
  • 19. Actors val printerActor = actor { loop { receive { case s: String => println("I got a String: " + s) case i: Int => println("I got an Int: " + i.toString) case _ => println(" I don’t know what I got ") } } } printerActor ! "hi there“ // prints “I got a String: hi there” printerActor ! 23 // prints “I got an Int: 23” printerActor ! 3.33 // prints “I don’t know what I got”
  • 20. The ecosystem
  • 21. Who is using Scala ?
  • 22. Norbert by LinkedIn • Norbert is a framework written in Scala that allows to write asynchronous, message based, client/server applications • Built on Apache ZooKeeper and JBoss Netty, Norbert to make it easy to build a cluster aware application • Provides out of the box support for notifications of cluster topology changes, application specific routing, load balancing and partitioned workload
  • 23. • Akka is a framework that allows to write simpler concurrent (yet correct) applications • It provides a higher level of abstraction for writing concurrent and distributed systems through (remote) actors • It implements Software Transactional Memory (STM) turning the Java heap into a transactional data set with begin/commit/rollback semantic • Fault-tolerant adopting the "Let it crash" / "Embrace failure" model
  • 24. SBT (simple-build-tool) • Sbt is a build tool written in Scala • Uses the same directory structure as Maven for source files • Uses Ivy to resolve dependencies • Compatible with Maven configuration files • Supports testing with ScalaTest • Parallel task execution, including parallel test execution
  • 25. Thanks a lot Happy Scala programming! Mario Fusco mario.fusco@gmail.com Twitter: @mariofusco