SlideShare a Scribd company logo
1 of 116
Download to read offline
Scala workshop
                   Created by
    Fredrik Vraalsen (fredrik@vraalsen.no)
                       and
  Alf Kristian Støyle (alf.kristian@gmail.com)

                   Adapted
Bert Van Vreckem (bert.vanvreckem@hogent.be)
If I were to pick a language to use
today other than Java, it would be
                Scala.

          James Gosling
Scala, it must be stated, is the current heir
apparent to the Java throne. No other language
   on the JVM seems as capable of being a
   "replacement for Java" as Scala, and the
momentum behind Scala is now unquestionable.

      Charlies Olivier Nutter - JRuby lead
Though my tip though for the long term
  replacement of javac is Scala. I'm very
   impressed with it! I can honestly say if
someone had shown me the Programming
 in Scala book by by Martin Odersky, Lex
   Spoon & Bill Venners back in 2003 I'd
    probably have never created Groovy.

             James Strachen
public class Person {
    private int age;
    private String name;

      public Person(int age, String name) {
        this.age = age;
        this.name = name;
      }

      public int getAge() {
        return this.age;
      }

      public void setAge(int age) {
        this.age = age;
      }

      public String getName() {
        return this.name;
      }

      public void setName(String name) {
        this.name = name;
      }
  }



class Person(var age: Int,
             var name: String)
List<Person> persons = ...
List<Person> adults = new LinkedList<Person>();
List<Person> kids = new LinkedList<Person>();
for (Person person : persons) {
  if (person.getAge() < 18) {
    kids.add(person);
  } else {
    adults.add(person);
  }
}




     val (kids, adults) =
       persons.partition(_.age < 18)
String s = "!em esreveR";
System.out.println(s.reverse());




     val s = "!em esreveR"
     println(s.reverse)

     => Reverse me!
BufferedReader reader = null;
try {
  reader = new BufferedReader(new FileReader("f.txt"));
  System.out.println(reader.readLine());
} finally {
  if (reader != null) {
    try {
      reader.close();
    } catch (IOException e) {
      // Exception on close, ignore
    }
  }
}



using(new BufferedReader(new FileReader("f.txt"))) {
    reader => println(reader.readLine())
}
I will never forget these words: "With great power
  comes great responsibility." This is my gift, my
         curse. Who am I? I'm Spider-man.
val myList = List(1, 2, 3)
val res = (10 /: myList)(_+_)


=> ??
Scala
●   Object oriented and functional
●   Statically typed
●   Java compatible
    ●   Complies to Java bytecode (and CLR)
    ●   Existing libraries/frameworks
●   Better Java
Todays schedule
●   Basic syntax
●   REPL, IDEs and setup
●   First class functions
●   Pattern matching
●   OO and traits
●   Functional programming
●   Higher order functions
Scala basics
;
Type definitions
Scala               Java

s: String           String s
i: Int              int i / Integer i
Variables
Scala:                   Java:

val s = "Hello World"    public final String s =
                           "Hello World";

var i = 1
                         public int i = 1;

private var j = 3
                         private int j = 3;
Methods (3)
Scala:                        Java:

override def toString = ...   @Override
                              public String toString()
                                {...}
Classes and constructors
Scala:                   Java:

class Person(val name:   public class Person {
  String)                   private final String
                              name;
                            public Person(String
                              name) {
                               this.name = name;
                            }
                            public String getName() {
                               return name;
                            }
                         }
Traits (= Interface + Mixin)
Scala:                        Java:

trait Shape {                 interface Shape {
   def area: Double              public double area();
}                             }

class Circle extends Object   public class Circle extends
  with Shape                    Object implements Shape
No “static” in Scala
Scala:                           Java:

object PersonUtil {              public class PersonUtil {
  val ageLimit = 18                 public static final int
                                      AGE_LIMIT = 18;

    def countPersons(                public static int
      persons: List[Person]) =         countPersons(
      ...                                List<Person> persons)
}                                    {
                                         ...
                                     }
                                 }
While-loops
Scala:                 Java:

while (true) {         while (true) {
    ...                    ...
}                      }
Exceptions
Scala:                    Java:

throw new                 throw new
  Exception(“...”)          Exception(“...”)

try {                     try {
} catch {                 } catch (IOException e) {
   case e: IOException       ...
     => ...               } finally {
} finally {               }
}
Varargs
def foo(values: String*){ }     public void foo(String... values){ }


foo("bar", "baz")               foo("bar", "baz");


val arr = Array("bar", "baz")   String[] arr =
                                  new String[]{"bar", "baz"}
foo(arr: _*)                    foo(arr);
(Almost) everything is an expression
val res = if (foo) x else y


val res = for (i <- 1 to 10) yield i
   // List(1, ..., 10)


val res = try { x } catch { ...; y }
 finally { } // x or y
Generics
Scala:             Java:

List[String]       List<String>
Tuples
Scala:                   Java:

val tuple: Tuple2[Int,   Pair<Integer, String> tuple
  String] =                = new Pair<Integer,
                           String>(1, “apple”)
  (1, “apple”)


val quadruple =
                         ... yeah right... ;-)
  (2, “orange”, 0.5d,
    false)
Packages
Scala:                  Java:

package mypackage       package mypackage;
...                     ...
Imports
Scala:                        Java:

import java.util.{List,       import java.util.List
  ArrayList}
                              import java.util.ArrayList


import java.io._
                              import java.io.*
import scala.util.Sorting._   ???

import java.sql.{Date =>      ???
  SDate}
REPL, IDE and setup
REPL: Read-Eval-Print Loop
●   Command line shell for on-the-fly execution of
    Scala statements
●
    $ cd ${SCALA_HOME}/bin
    $ scala
    ●   Windows, e.g. C:Program FilesScala 2.8.0
    ●   Linux, e.g. /opt/scala or /usr/local/scala
IDE
●   They are all !#$&§? compared to what you are
    used to with Java support
    ●   Netbeans (very good) but bad in other areas...
    ●   IntelliJ IDEA (pretty good) but slow compilation,
        bonus community edition is free (with Scala)
    ●   Eclipse (not all that good) but very fast when
        working
Netbeans 6.9.x installation
●   Download plugins
    http://sf.net/projects/erlybird/files/nb-scala/6.9v1.1.0/
●   In NetBeans "Tools" | "Plugins",
     ●   click on "Downloaded" tab title,
     ●   click on "Add Plugins..." button,
     ●   choose the directory where the Scala plugins are unzipped,
     ●   select all listed *.nbm files, following the instructions.
●   Set ${SCALA_HOME} or %SCALA_HOME% environment variable
●   Edit ${NETBEANS_HOME}/etc/netbeans.conf
     ●   Add "-J-Dscala.home=/opt/scala" to
         netbeans_default_options
●   More info: http://wiki.netbeans.org/Scala
Tasks (20 min)
●   Run REPL
    ●   Windows: %scala_home%/bin/scala
    ●   Linux: scala or /opt/scala/bin/scala
    ●   Execute a few statements
●   Copy & unpack
    'HeliumPublicCursussenNavorming
    ScalaScalaTraining.zip'
    ●   into 'DocumentenNetbeansProjects' (Windows)
    ●   Into '/home/student/NetbeansProjects' (Linux)
Tasks (20 min)
●   Run unit test in IDE (JUnit 4)
    ●   Open the 'ScalaTraining' project in NetBeans
    ●   Try to compile and test the project (should work)
    ●   scalaexamples.intro.MyFirstTest
         –   Create a failing test
         –   Make it run
●   Make the two classes scalaexamples/intro/HelloWorld.scala
    print “Hello world”. What is the difference?
●   Remove comments from @Test for the methods in
    scalaexamples/intro/CreateStuffTest.scala. Make tests pass.
First class functions
First class functions

val even = Function[Int, Boolean] {
    def apply(i: Int) = i % 2 == 0
}

val even: (Int => Boolean) = (i: Int) => i % 2 == 0
val even = (i: Int) => i % 2 == 0

even.apply(42)       // true
even(13)             // false
First class functions
val numbers = List(1, 2, 3, 4, 5)

numbers.filter(even)                // List(2, 4)

numbers.filter((i: Int) => i > 2)   // List(3, 4, 5)
numbers.filter(i => i > 2)          // List(3, 4, 5)
numbers.filter(_ > 2)               // List(3, 4, 5)
Collections


numbers.filter(i =>   i   > 2)   //   List(3, 4, 5)
numbers.find(i => i   >   2)     //   Some(3)
numbers.exists(i =>   i   > 2)   //   true
numbers.forall(i =>   i   > 2)   //   false

numbers.map(i => i * 2)          // List(2, 4, 6, 8, 10)

numbers.foldLeft(0) { (a, b) => a + b }          // 15
Closures

val people = List(Person(“Alf”), Person(“Fredrik”))

var name = “Fredrik”
val nameFilter = (p: Person) => p.name == name

people.filter(nameFilter)     // Person(“Fredrik”)
name = “Alf”
people.filter(nameFilter)     // Person(“Alf”)
Tasks (30 min)
●   Open the 'first-class-functions' project
●   Tests in package
    scalaexamples.firstclassfunctions
●   Add @Test to one and one method
●   Follow instructions in the code
●   Make the tests pass
Pattern matching
myObject   match {
  case 1   => println("First was hit")
  case 2   => println("Second was Hit")
  case _   => println("Unknown")
}
myObject match {
   case i: Int => println("Found an int")
   case s: String => println("Found a String")
   case _ => println("Unknown")
 }
myObject match {
   case i: Int => println("Found an int")
   case s: String => println("Found a String")
   case other => println("Unknown " + other)
 }
myObject match {
   case i: Int if i == 1 => println("Found an int")
   case s: String => println("Found a String")
   case other => println("Unknown " + other)
 }
val res = myObject match {
    case i: Int if i == 1 => "Found an int"
    case s: String => "Found a String"
    case other => "Unknown " + other
}
val res = myObject match {
    case (first, second) => second
    case (first, second, third) => third
}
val mathedElement = list match {
  case List(firstElement, lastElement) => lastElement
  case List(firstElement, _ *) => firstElement
  case _ => "failed"
}
def length(list: List[_]): Int =
  list match {
    case Nil => 0
    case head :: tail => 1 + length(tail)
  }
public static Integer getSecondOr0(List<Integer> list) {
    if (list != null && list.size() >= 2) {
        return list.get(1);
    } else {
        return 0;
    }
}




def second_or_0(list:List[Int]) = list match {
  case List(_, x, _*) => x
  case _ => 0
}
Case classes
●   Class types that can be used in pattern
    matching
●   Generated into your class:
    ●   equals
    ●   hashCode
    ●   toString
    ●   getters (and optionally setters)
    ●   ++
abstract class Person(name: String)
case class Man(name: String) extends Person(name)
case class Woman(name: String, children: List[Person])
  extends Person(name)
p match {
  case Man(name) => println("Man with name " + name)
  case Woman(name, children) => println("Woman with name "
                              + name + " and with " +
                                children.size + " children")
}
val regex = """(d+)(w+)""".r

val myString = ...

val res: String = myString match {
  case regex(digits, word) => digits
  case _ => "None"
}
val regex = """(d+)(w+)""".r

val myString = ...

val res: Option[String] = myString match {
  case regex(digit, word) => Some(digit)
  case _ => None
}
The Option type, never again
           NullPointerException
●   Option has two possible values
    ●   Some(value)
    ●   None



    val someOption: Option[String] = Some("value")
    val noOption:   Option[String] = None
def getValue(s: Any): Option[String]




getValue(object) match {
  case Some(value) => println(value)
  case None => println("Nothing")
}



val result = getValue(object).getOrElse("Nothing")
Tasks (30 min)
●   Open the 'pattern-matching' project
●   Tests in package
    scalaexamples.patternmatching
●   Add @Test to one and one method
●   Follow instructions in the code
●   Make the tests pass
Object orientation and
        traits
Annotations – not marker interfaces


       @serializable class Person

       @SerialVersionUID(1) class Person

       @cloneable class Person

       @remote class Service
object
●   object is a “singleton” class
    ●    Call may look like static method calls in Java
    ●    Can inherit from other classes and traits
    ●    Can be passed as a reference

        object MyObject {
          def foo = "bar"
        }

        var baz = MyObject.foo
        val personObject = MyObject
        baz = personObject.foo
Companion object
●   Can read the companion class' private fields
●   Has to be in the same source file

class Person(private val age: Int)

object Person {
  def getPersonAge(p: Person) = p.age
}

val personInstance = new Person(30)
val age = Person.getPersonAge(personInstance)
Magical apply


class Person private(val age: Int)

object Person {
  def apply(age: Int) = new Person(age)
}

var personInstance = Person.apply(30)
    personInstance = Person(30)
Not built in, clever use of apply



val myList = List(1, 2, 3)
val mySet = Set(1, 2, 3)
val myMap = Map(1 -> "one", 2 -> "two")
Constructors
●   Always one primary constructor
●   Parameters are automatically instance variables
●   Class “body” is the primary constructors content
●   Auxiliary constructors MUST call or chain to primary
    constructor
    class MyClass(myString: String, myInt: Int)

        val myOtherInt = 10
        println("In main body")

    }
Auxiliary constructors
class MyClass(myString: String, myInt: Int) {

    def this(myString: String) = this(myString, 0)

    def this() = {
      this("foo")
      println("In default constructor")
    }

}
Inheritance


class MyClass(myString: String)

class MySubClass(myString: String, myInt: Int)
      extends MyClass(myString) {

    println("MyString: '" + myString +
            "', MyInt: '" + myInt + "'")

}
Inheritance
●   Single class inheritance
●   Multiple trait mixins
Syntax


class Person extends AnyRef
             with java.io.Serializable
             with java.rmi.Remote

class Person extends java.io.Serializable
             with java.rmi.Remote
Traits
●   “Multiple inheritance done right”
●   Implement methods
●   Initialized fields
●   Abstract methods
●   Abstract fields
●   Abstract types
●   Does not have constructors
●   Call to super → strict semantics
scala.Ordered trait

trait Ordered[A] {
  def compare(that: A): Int

    def   <    (that:   A):   Boolean   =   (this   compare   that)   <    0
    def   >    (that:   A):   Boolean   =   (this   compare   that)   >    0
    def   <=   (that:   A):   Boolean   =   (this   compare   that)   <=   0
    def   >=   (that:   A):   Boolean   =   (this   compare   that)   >=   0
}
The Ordered trait

class Person(private val age: Int)
      extends Ordered[Person] {

    def compare(other: Person) =
      this.age - other.age
}


val person1 = new Person(21)
val person2 = new Person(31)
person1 < person2 // true
person1 <= person2 // true
person1 >= person2 // false
“Dynamic mixins”


class Person(age: Int) {
  override def toString = "my age is " + age
}

trait MyTrait {
  override def toString = "I am sure " +
                          super.toString
}

val person = new Person(30) with MyTrait
println(person)

=> I am sure my age is 30
is-a vs has-a
●   Inheritance as usual
●   Easier to implement has-a
●   Inheritance vs composition
Tasks (30 min)
●   Open 'oo-traits' project
●   Tests under scalaexamples
    ●   companionobject
    ●   inheritance
    ●   traits
●   Add @Test to one and one method
●   Follow instructions in code
●   Make tests pass
Functional programming
“Functional programming”
●   First class functions
●   Pattern matching
●   Higher order functions
Functional programming
●   Purity
●   Mathematical functions have no side effects
    ●   f(x) = 2x + 3
    ●   y = sin(x)
●   Mathematical functions always give same result
    for same input
    ●   Only immutable objects (and object graphs)
In practice
●   All fields must be immutable
●   All methods must return something
●   No side-effects from method calls
    ●
        println("...") is also a side effect!
List
●   head :: tail
●   Prepends to the head of the list
●   Other operations (filter, map, remove,
    partition...) returns a new List instance
scala.collection.immutable
●   ...or scala.collection.mutable
●   Pick your poison!
Scala 2.8
●   Case classes get copy methods
●   Constructors and methods get
    ●   named parameters
        def resize(width: Int, height: Int) = { ... }
        resize(height = 42, width = 120)
    ●   default parameters
        def f(elems: List[Int], x: Int = 0,
              cond: Boolean = true)
        f(List(1))
        f(Nil, cond = false)
Strive to be pure
●   Parallelization and concurrency (no
    synchronization)
●   Usually easier to find errors (a lot less state)
●   Easier to test
Refactoring imperative style code
def printMultiTable () {
  var i = 1 // row
  while (i <= 10) {
    var j = 1 // column
    while (j <= 10) {
      val prod = (i * j).toString
      var k = prod.length // padding
      while (k < 4) {              1    2    3    4    5    6    7    8    9 10
        print(" ")                 2    4    6    8   10   12   14   16   18 20
        k += 1                     3    6    9   12   15   18   21   24   27 30
      }                            4    8   12   16   20   24   28   32   36 40
      print(prod)                  5   10   15   20   25   30   35   40   45 50
      j += 1                       6   12   18   24   30   36   42   48   54 60
                                   7   14   21   28   35   42   49   56   63 70
    }
                                   8   16   24   32   40   48   56   64   72 80
    println()                      9   18   27   36   45   54   63   72   81 90
    i += 1                        10   20   30   40   50   60   70   80   90 100
  }
}
Refactoring imperative style code
●   Side effect: printing table
    ●   Functional style: return String
●   Harder to test
    ●   How to test result of println()?
●   While loop & vars
    ●   Functional style: val, for expressions, helper
        functions
    ●   Helper functions can be tested separately
Functional style multiplication table

    def makeRowSeq(row: Int) =
      for (col <- 1 to 10) yield {
        val prod = (row * col).toString
        val padding = " " * (4 - prod.length)
        padding + prod
      }

    def makeRow(row: Int) = makeRowSeq(row).mkString

    def multiTable = {
      val tableSeq =
        for (row <- 1 to 10)
          yield makeRow(row)
      tableSeq.mkString("n")
    }
A closer look at Collections
 ●   Overview of collection traits




http://www.decodified.com/scala/collections-api.xml
Traversable
●    One abstract method:
     def foreach[U](f: Elem => U)
●    50+ concrete methods
      ●   Addition, mapping, conversion, copying, size info,
          element retrieval, sub-collection retrieval,
          subdivision, element tests, folds, string operations,
          view



    http://www.scala-lang.org/api/
    http://www.scala-lang.org/docu/files/collections-api/
Iterable
●   Abstract method iterator
●   Default implementation of foreach:
    def foreach[U](f:Elem => U): Unit = {
      val it = iterator
      while (it.hasNext) f(it.next())
    }
    ●   Subclasses may override
●   Some concrete methods
    ●   Subcollections, "zippers", comparison
Seq, IndexedSeq, LinearSeq
●   Sequence:
    ●   iterable that has a length,
    ●   elements have fixed index position, starting with 0
●   Operations:
    ●   Indexing (apply), search, addition, update, sorting,
        reversal, comparison, set operations
●   IndexedSeq, LinearSeq
    ●   No new operations, but different performance
         –   LinearSeq: efficient head, tail
         –   IndexedSeq: efficient apply, length
Sets, SortedSet
●   Set = iterable that contain no duplicates
    ●   Operations for tests, addition, removal, set
        operations
●   SortedSet
    ●   Iterator/foreach visit elements in given ordering
    ●   Default implementation: binary tree
Maps
●   Map = collection of pairs of keys and values
    e.g. Map("x" -> 24, "y" -> 25, "z" -> 26)
    ●   Operations for lookup, addition/update, removal,
        subcollections, transformations
Immutable collections




http://www.decodified.com/scala/collections-api.xml
Mutable collections
Higher order functions
Higher order functions
●   Functions which take functions as parameters
    and/or return functions
Higher order functions
Short summary of first class functions:
val even: (Int => Boolean) = (i: Int) => i % 2 == 0



Same type definition:
def test(numbers: List[Int], f: Int => Boolean) = ...



Call:
test(List(1, 2, 3), (i: Int) => i % 2 == 0)
Higher order functions

def test(numbers: List[Int],
         f: Int => Boolean) =
  numbers.map(tall => f(tall))


// List[Boolean]
Higher order functions
Functions with several parameters must list them
in parenthesis:


def test(l: List[String],
         f: (Int, String) => Boolean)
call-by-value vs. call-by-name
●   by-value: expressions are evaluated before
    being passed to the function

●   by-name: expressions evaluated inside function
    ●   nice when computationally expensive
    ●   possible to create nice APIs
call-by-value vs. call-by-name
Example: Logging


def thisTakesTime = {
    println(“Slow computation”)
    “result”
}
logger.debug(thisTakesTime())
call-by-value
def debug(s: String) {
      println(“debug”)
      if (logLevel <= DEBUG) println(s)
}


// Slow computation
// debug
// result
call-by-name
def debug(s: => String) {
      println(“debug”)
      if (logLevel <= DEBUG) println(s)
}


// debug
// Slow computation
// result
BufferedReader reader = null;
try {
  reader = new BufferedReader(new FileReader("f.txt"));
  System.out.println(reader.readLine());
} finally {
  if (reader != null) {
    try {
      reader.close();
    } catch (IOException e) {
      // Exception on close, ignore
    }
  }
}


using(new BufferedReader(new FileReader("f.txt"))) {
  reader => println(reader.readLine())
}
def using[T <: { def close() }, A]
         (closeable: T)
         (f: T => A) = {
  try {
    f(closeable)
  } finally {
    if (closeable != null) {
      try {
        closeable.close()
      }
      catch {
        case e: Exception =>
          // Do something clever!?
      }
    }
  }
}
Tasks (30 min)
●   Open 'higher-order-functions' project
●   Tests in scalaexamples.higherorderfunctions
●   Add @Test to one and one method
●   Implement missing functions in PersonFilter
    and so on.
●   Follow instructions in code
●   Make tests pass
Where to go next?
Advanced topics
●   Type inference
●   Implicit conversions
●   Extractors
●   Annotations
●   XML
●   Parallel programming with Actors
●   Domain Specific Languages (DSLs)
●   GUI programming with Scala Swing
Exercises
●   Solutions to exercises:
    http://github.com/javaBin/scala-training-code/zipball/solutions
●   99 Scala Problems:
    http://aperiodic.net/phil/scala/s-99/
Bert's Scala bookmarks:
http://www.delicious.com/bertvv/scala
A lot of blogs




http://www.planetscala.com/
Mailing lists

        scala@listes.epfl.ch
  scala-announce@listes.epfl.ch
     scala-user@listes.epfl.ch
    scala-debate@listes.epfl.ch
     scala-tools@listes.epfl.ch
   scala-internals@listes.epfl.ch

http://www.scala-lang.org/node/199
Several books




                         +++
          http://www.scala-lang.org/node/959
Creative Commons




   http://programming-scala.labs.oreilly.com/index.html
http://www.scala-lang.org/
Creative Commons
         Attribution 3.0 Unported

                     Scala Training Code
       http://github.com/javaBin/scala-training-code
  git clone git://github.com/javaBin/scala-training-code



                     Scala Training Slides
       http://github.com/javaBin/scala-training-slides
git clone git://github.com/javaBin/scala-training-slides.git

More Related Content

What's hot

Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: NotesRoberto Casadei
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Jonas Bonér
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldBTI360
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdfHiroshi Ono
 
Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008Yardena Meymann
 
Scaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with ScalaScaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with ScalaOstap Andrusiv
 
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...Sanjeev_Knoldus
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesTomer Gabel
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersMiles Sabin
 
Procedure Typing for Scala
Procedure Typing for ScalaProcedure Typing for Scala
Procedure Typing for Scalaakuklev
 

What's hot (17)

Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: Notes
 
1.2 scala basics
1.2 scala basics1.2 scala basics
1.2 scala basics
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
 
All about scala
All about scalaAll about scala
All about scala
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
Scala fundamentals
Scala fundamentalsScala fundamentals
Scala fundamentals
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008
 
Scaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with ScalaScaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with Scala
 
Scala on Android
Scala on AndroidScala on Android
Scala on Android
 
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
 
Scala 2013 review
Scala 2013 reviewScala 2013 review
Scala 2013 review
 
camel-scala.pdf
camel-scala.pdfcamel-scala.pdf
camel-scala.pdf
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
 
Procedure Typing for Scala
Procedure Typing for ScalaProcedure Typing for Scala
Procedure Typing for Scala
 

Viewers also liked

Scala meetup - Intro to spark
Scala meetup - Intro to sparkScala meetup - Intro to spark
Scala meetup - Intro to sparkJavier Arrieta
 
One vagrantfile to rule them all
One vagrantfile to rule them allOne vagrantfile to rule them all
One vagrantfile to rule them allBert Van Vreckem
 
Spark tutorial @ KCC 2015
Spark tutorial @ KCC 2015Spark tutorial @ KCC 2015
Spark tutorial @ KCC 2015Jongwook Woo
 
HDFS & MapReduce
HDFS & MapReduceHDFS & MapReduce
HDFS & MapReduceSkillspeed
 
Spark手把手:[e2-spk-s01]
Spark手把手:[e2-spk-s01]Spark手把手:[e2-spk-s01]
Spark手把手:[e2-spk-s01]Erhwen Kuo
 
Spark手把手:[e2-spk-s02]
Spark手把手:[e2-spk-s02]Spark手把手:[e2-spk-s02]
Spark手把手:[e2-spk-s02]Erhwen Kuo
 
Spark手把手:[e2-spk-s03]
Spark手把手:[e2-spk-s03]Spark手把手:[e2-spk-s03]
Spark手把手:[e2-spk-s03]Erhwen Kuo
 
Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)Calvin Cheng
 
Spark手把手:[e2-spk-s04]
Spark手把手:[e2-spk-s04]Spark手把手:[e2-spk-s04]
Spark手把手:[e2-spk-s04]二文 郭
 
Run Your First Hadoop 2.x Program
Run Your First Hadoop 2.x ProgramRun Your First Hadoop 2.x Program
Run Your First Hadoop 2.x ProgramSkillspeed
 
Getting started with Apache Spark
Getting started with Apache SparkGetting started with Apache Spark
Getting started with Apache SparkHabib Ahmed Bhutto
 
Spark tutorial py con 2016 part 2
Spark tutorial py con 2016   part 2Spark tutorial py con 2016   part 2
Spark tutorial py con 2016 part 2David Taieb
 
Data Science with Spark
Data Science with SparkData Science with Spark
Data Science with SparkKrishna Sankar
 
Advanced Data Science on Spark-(Reza Zadeh, Stanford)
Advanced Data Science on Spark-(Reza Zadeh, Stanford)Advanced Data Science on Spark-(Reza Zadeh, Stanford)
Advanced Data Science on Spark-(Reza Zadeh, Stanford)Spark Summit
 
Spark tutorial pycon 2016 part 1
Spark tutorial pycon 2016   part 1Spark tutorial pycon 2016   part 1
Spark tutorial pycon 2016 part 1David Taieb
 

Viewers also liked (20)

Scala+RDD
Scala+RDDScala+RDD
Scala+RDD
 
ScalaTrainings
ScalaTrainingsScalaTrainings
ScalaTrainings
 
Scala+spark 2nd
Scala+spark 2ndScala+spark 2nd
Scala+spark 2nd
 
Scala meetup - Intro to spark
Scala meetup - Intro to sparkScala meetup - Intro to spark
Scala meetup - Intro to spark
 
One vagrantfile to rule them all
One vagrantfile to rule them allOne vagrantfile to rule them all
One vagrantfile to rule them all
 
Spark tutorial @ KCC 2015
Spark tutorial @ KCC 2015Spark tutorial @ KCC 2015
Spark tutorial @ KCC 2015
 
NYC_2016_slides
NYC_2016_slidesNYC_2016_slides
NYC_2016_slides
 
HDFS & MapReduce
HDFS & MapReduceHDFS & MapReduce
HDFS & MapReduce
 
Spark手把手:[e2-spk-s01]
Spark手把手:[e2-spk-s01]Spark手把手:[e2-spk-s01]
Spark手把手:[e2-spk-s01]
 
Spark手把手:[e2-spk-s02]
Spark手把手:[e2-spk-s02]Spark手把手:[e2-spk-s02]
Spark手把手:[e2-spk-s02]
 
Spark手把手:[e2-spk-s03]
Spark手把手:[e2-spk-s03]Spark手把手:[e2-spk-s03]
Spark手把手:[e2-spk-s03]
 
Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)
 
Spark手把手:[e2-spk-s04]
Spark手把手:[e2-spk-s04]Spark手把手:[e2-spk-s04]
Spark手把手:[e2-spk-s04]
 
Dev Ops Training
Dev Ops TrainingDev Ops Training
Dev Ops Training
 
Run Your First Hadoop 2.x Program
Run Your First Hadoop 2.x ProgramRun Your First Hadoop 2.x Program
Run Your First Hadoop 2.x Program
 
Getting started with Apache Spark
Getting started with Apache SparkGetting started with Apache Spark
Getting started with Apache Spark
 
Spark tutorial py con 2016 part 2
Spark tutorial py con 2016   part 2Spark tutorial py con 2016   part 2
Spark tutorial py con 2016 part 2
 
Data Science with Spark
Data Science with SparkData Science with Spark
Data Science with Spark
 
Advanced Data Science on Spark-(Reza Zadeh, Stanford)
Advanced Data Science on Spark-(Reza Zadeh, Stanford)Advanced Data Science on Spark-(Reza Zadeh, Stanford)
Advanced Data Science on Spark-(Reza Zadeh, Stanford)
 
Spark tutorial pycon 2016 part 1
Spark tutorial pycon 2016   part 1Spark tutorial pycon 2016   part 1
Spark tutorial pycon 2016 part 1
 

Similar to Workshop Scala

1.2 scala basics
1.2 scala basics1.2 scala basics
1.2 scala basicswpgreenway
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvmIsaias Barroso
 
Intro to scala
Intro to scalaIntro to scala
Intro to scalaJoe Zulli
 
1.1 motivation
1.1 motivation1.1 motivation
1.1 motivationwpgreenway
 
2.1 recap from-day_one
2.1 recap from-day_one2.1 recap from-day_one
2.1 recap from-day_onefuturespective
 
Scala at GenevaJUG by Iulian Dragos
Scala at GenevaJUG by Iulian DragosScala at GenevaJUG by Iulian Dragos
Scala at GenevaJUG by Iulian DragosGenevaJUG
 
Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Jesper Kamstrup Linnet
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersMiles Sabin
 
1.2 Scala Basics
1.2 Scala Basics1.2 Scala Basics
1.2 Scala Basicsretronym
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaMichael Stal
 
Java patterns in Scala
Java patterns in ScalaJava patterns in Scala
Java patterns in ScalaRadim Pavlicek
 
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developersSoftshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developersMatthew Farwell
 
Getting Started With Scala
Getting Started With ScalaGetting Started With Scala
Getting Started With ScalaMeetu Maltiar
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalMichael Stal
 

Similar to Workshop Scala (20)

1.2 scala basics
1.2 scala basics1.2 scala basics
1.2 scala basics
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvm
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
 
1.1 motivation
1.1 motivation1.1 motivation
1.1 motivation
 
Scala in a nutshell by venkat
Scala in a nutshell by venkatScala in a nutshell by venkat
Scala in a nutshell by venkat
 
2.1 recap from-day_one
2.1 recap from-day_one2.1 recap from-day_one
2.1 recap from-day_one
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 
Scala at GenevaJUG by Iulian Dragos
Scala at GenevaJUG by Iulian DragosScala at GenevaJUG by Iulian Dragos
Scala at GenevaJUG by Iulian Dragos
 
Scala - en bedre Java?
Scala - en bedre Java?Scala - en bedre Java?
Scala - en bedre Java?
 
Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
 
1.2 Scala Basics
1.2 Scala Basics1.2 Scala Basics
1.2 Scala Basics
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scala
 
Java patterns in Scala
Java patterns in ScalaJava patterns in Scala
Java patterns in Scala
 
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developersSoftshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
 
Getting Started With Scala
Getting Started With ScalaGetting Started With Scala
Getting Started With Scala
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
 
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
 
Scala - core features
Scala - core featuresScala - core features
Scala - core features
 

More from Bert Van Vreckem

Linux troubleshooting tips
Linux troubleshooting tipsLinux troubleshooting tips
Linux troubleshooting tipsBert Van Vreckem
 
Een fileserver opzetten met Samba
Een fileserver opzetten met SambaEen fileserver opzetten met Samba
Een fileserver opzetten met SambaBert Van Vreckem
 
Linux Enterprise - inleiding cursus, 5 trends in systeembeheer
Linux Enterprise - inleiding cursus, 5 trends in systeembeheerLinux Enterprise - inleiding cursus, 5 trends in systeembeheer
Linux Enterprise - inleiding cursus, 5 trends in systeembeheerBert Van Vreckem
 
A Reinforcement Learning Approach for Hybrid Flexible Flowline Scheduling Pro...
A Reinforcement Learning Approach for Hybrid Flexible Flowline Scheduling Pro...A Reinforcement Learning Approach for Hybrid Flexible Flowline Scheduling Pro...
A Reinforcement Learning Approach for Hybrid Flexible Flowline Scheduling Pro...Bert Van Vreckem
 
Gebruikers, groepen en permissies
Gebruikers, groepen en permissiesGebruikers, groepen en permissies
Gebruikers, groepen en permissiesBert Van Vreckem
 
Een literatuurstudie maken: hoe & waarom
Een literatuurstudie maken: hoe & waaromEen literatuurstudie maken: hoe & waarom
Een literatuurstudie maken: hoe & waaromBert Van Vreckem
 

More from Bert Van Vreckem (9)

Linux troubleshooting tips
Linux troubleshooting tipsLinux troubleshooting tips
Linux troubleshooting tips
 
Een fileserver opzetten met Samba
Een fileserver opzetten met SambaEen fileserver opzetten met Samba
Een fileserver opzetten met Samba
 
Linux Enterprise - inleiding cursus, 5 trends in systeembeheer
Linux Enterprise - inleiding cursus, 5 trends in systeembeheerLinux Enterprise - inleiding cursus, 5 trends in systeembeheer
Linux Enterprise - inleiding cursus, 5 trends in systeembeheer
 
A Reinforcement Learning Approach for Hybrid Flexible Flowline Scheduling Pro...
A Reinforcement Learning Approach for Hybrid Flexible Flowline Scheduling Pro...A Reinforcement Learning Approach for Hybrid Flexible Flowline Scheduling Pro...
A Reinforcement Learning Approach for Hybrid Flexible Flowline Scheduling Pro...
 
Gebruikers, groepen en permissies
Gebruikers, groepen en permissiesGebruikers, groepen en permissies
Gebruikers, groepen en permissies
 
Wachtwoorden in Linux
Wachtwoorden in LinuxWachtwoorden in Linux
Wachtwoorden in Linux
 
Een literatuurstudie maken: hoe & waarom
Een literatuurstudie maken: hoe & waaromEen literatuurstudie maken: hoe & waarom
Een literatuurstudie maken: hoe & waarom
 
Workshop latex
Workshop latexWorkshop latex
Workshop latex
 
Clean, effective java
Clean, effective javaClean, effective java
Clean, effective java
 

Recently uploaded

Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesVijayaLaxmi84
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
How to Uninstall a Module in Odoo 17 Using Command Line
How to Uninstall a Module in Odoo 17 Using Command LineHow to Uninstall a Module in Odoo 17 Using Command Line
How to Uninstall a Module in Odoo 17 Using Command LineCeline George
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - I-LEARN SMART WORLD - CẢ NĂM - CÓ FILE NGHE (BẢN...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - I-LEARN SMART WORLD - CẢ NĂM - CÓ FILE NGHE (BẢN...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - I-LEARN SMART WORLD - CẢ NĂM - CÓ FILE NGHE (BẢN...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - I-LEARN SMART WORLD - CẢ NĂM - CÓ FILE NGHE (BẢN...Nguyen Thanh Tu Collection
 
4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptxmary850239
 
Comparative Literature in India by Amiya dev.pptx
Comparative Literature in India by Amiya dev.pptxComparative Literature in India by Amiya dev.pptx
Comparative Literature in India by Amiya dev.pptxAvaniJani1
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17Celine George
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6Vanessa Camilleri
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfChristalin Nelson
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxAnupam32727
 

Recently uploaded (20)

Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their uses
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
Chi-Square Test Non Parametric Test Categorical Variable
Chi-Square Test Non Parametric Test Categorical VariableChi-Square Test Non Parametric Test Categorical Variable
Chi-Square Test Non Parametric Test Categorical Variable
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
How to Uninstall a Module in Odoo 17 Using Command Line
How to Uninstall a Module in Odoo 17 Using Command LineHow to Uninstall a Module in Odoo 17 Using Command Line
How to Uninstall a Module in Odoo 17 Using Command Line
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - I-LEARN SMART WORLD - CẢ NĂM - CÓ FILE NGHE (BẢN...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - I-LEARN SMART WORLD - CẢ NĂM - CÓ FILE NGHE (BẢN...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - I-LEARN SMART WORLD - CẢ NĂM - CÓ FILE NGHE (BẢN...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - I-LEARN SMART WORLD - CẢ NĂM - CÓ FILE NGHE (BẢN...
 
Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"
 
4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx
 
Comparative Literature in India by Amiya dev.pptx
Comparative Literature in India by Amiya dev.pptxComparative Literature in India by Amiya dev.pptx
Comparative Literature in India by Amiya dev.pptx
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
 
How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdf
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
 

Workshop Scala

  • 1. Scala workshop Created by Fredrik Vraalsen (fredrik@vraalsen.no) and Alf Kristian Støyle (alf.kristian@gmail.com) Adapted Bert Van Vreckem (bert.vanvreckem@hogent.be)
  • 2. If I were to pick a language to use today other than Java, it would be Scala. James Gosling
  • 3. Scala, it must be stated, is the current heir apparent to the Java throne. No other language on the JVM seems as capable of being a "replacement for Java" as Scala, and the momentum behind Scala is now unquestionable. Charlies Olivier Nutter - JRuby lead
  • 4. Though my tip though for the long term replacement of javac is Scala. I'm very impressed with it! I can honestly say if someone had shown me the Programming in Scala book by by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I'd probably have never created Groovy. James Strachen
  • 5. public class Person { private int age; private String name; public Person(int age, String name) { this.age = age; this.name = name; } public int getAge() { return this.age; } public void setAge(int age) { this.age = age; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } } class Person(var age: Int, var name: String)
  • 6. List<Person> persons = ... List<Person> adults = new LinkedList<Person>(); List<Person> kids = new LinkedList<Person>(); for (Person person : persons) { if (person.getAge() < 18) { kids.add(person); } else { adults.add(person); } } val (kids, adults) = persons.partition(_.age < 18)
  • 7. String s = "!em esreveR"; System.out.println(s.reverse()); val s = "!em esreveR" println(s.reverse) => Reverse me!
  • 8. BufferedReader reader = null; try { reader = new BufferedReader(new FileReader("f.txt")); System.out.println(reader.readLine()); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { // Exception on close, ignore } } } using(new BufferedReader(new FileReader("f.txt"))) { reader => println(reader.readLine()) }
  • 9. I will never forget these words: "With great power comes great responsibility." This is my gift, my curse. Who am I? I'm Spider-man.
  • 10. val myList = List(1, 2, 3) val res = (10 /: myList)(_+_) => ??
  • 11. Scala ● Object oriented and functional ● Statically typed ● Java compatible ● Complies to Java bytecode (and CLR) ● Existing libraries/frameworks ● Better Java
  • 12. Todays schedule ● Basic syntax ● REPL, IDEs and setup ● First class functions ● Pattern matching ● OO and traits ● Functional programming ● Higher order functions
  • 14. ;
  • 15. Type definitions Scala Java s: String String s i: Int int i / Integer i
  • 16. Variables Scala: Java: val s = "Hello World" public final String s = "Hello World"; var i = 1 public int i = 1; private var j = 3 private int j = 3;
  • 17. Methods (3) Scala: Java: override def toString = ... @Override public String toString() {...}
  • 18. Classes and constructors Scala: Java: class Person(val name: public class Person { String) private final String name; public Person(String name) { this.name = name; } public String getName() { return name; } }
  • 19. Traits (= Interface + Mixin) Scala: Java: trait Shape { interface Shape { def area: Double public double area(); } } class Circle extends Object public class Circle extends with Shape Object implements Shape
  • 20. No “static” in Scala Scala: Java: object PersonUtil { public class PersonUtil { val ageLimit = 18 public static final int AGE_LIMIT = 18; def countPersons( public static int persons: List[Person]) = countPersons( ... List<Person> persons) } { ... } }
  • 21. While-loops Scala: Java: while (true) { while (true) { ... ... } }
  • 22. Exceptions Scala: Java: throw new throw new Exception(“...”) Exception(“...”) try { try { } catch { } catch (IOException e) { case e: IOException ... => ... } finally { } finally { } }
  • 23. Varargs def foo(values: String*){ } public void foo(String... values){ } foo("bar", "baz") foo("bar", "baz"); val arr = Array("bar", "baz") String[] arr = new String[]{"bar", "baz"} foo(arr: _*) foo(arr);
  • 24. (Almost) everything is an expression val res = if (foo) x else y val res = for (i <- 1 to 10) yield i // List(1, ..., 10) val res = try { x } catch { ...; y } finally { } // x or y
  • 25. Generics Scala: Java: List[String] List<String>
  • 26. Tuples Scala: Java: val tuple: Tuple2[Int, Pair<Integer, String> tuple String] = = new Pair<Integer, String>(1, “apple”) (1, “apple”) val quadruple = ... yeah right... ;-) (2, “orange”, 0.5d, false)
  • 27. Packages Scala: Java: package mypackage package mypackage; ... ...
  • 28. Imports Scala: Java: import java.util.{List, import java.util.List ArrayList} import java.util.ArrayList import java.io._ import java.io.* import scala.util.Sorting._ ??? import java.sql.{Date => ??? SDate}
  • 29. REPL, IDE and setup
  • 30. REPL: Read-Eval-Print Loop ● Command line shell for on-the-fly execution of Scala statements ● $ cd ${SCALA_HOME}/bin $ scala ● Windows, e.g. C:Program FilesScala 2.8.0 ● Linux, e.g. /opt/scala or /usr/local/scala
  • 31. IDE ● They are all !#$&§? compared to what you are used to with Java support ● Netbeans (very good) but bad in other areas... ● IntelliJ IDEA (pretty good) but slow compilation, bonus community edition is free (with Scala) ● Eclipse (not all that good) but very fast when working
  • 32. Netbeans 6.9.x installation ● Download plugins http://sf.net/projects/erlybird/files/nb-scala/6.9v1.1.0/ ● In NetBeans "Tools" | "Plugins", ● click on "Downloaded" tab title, ● click on "Add Plugins..." button, ● choose the directory where the Scala plugins are unzipped, ● select all listed *.nbm files, following the instructions. ● Set ${SCALA_HOME} or %SCALA_HOME% environment variable ● Edit ${NETBEANS_HOME}/etc/netbeans.conf ● Add "-J-Dscala.home=/opt/scala" to netbeans_default_options ● More info: http://wiki.netbeans.org/Scala
  • 33. Tasks (20 min) ● Run REPL ● Windows: %scala_home%/bin/scala ● Linux: scala or /opt/scala/bin/scala ● Execute a few statements ● Copy & unpack 'HeliumPublicCursussenNavorming ScalaScalaTraining.zip' ● into 'DocumentenNetbeansProjects' (Windows) ● Into '/home/student/NetbeansProjects' (Linux)
  • 34. Tasks (20 min) ● Run unit test in IDE (JUnit 4) ● Open the 'ScalaTraining' project in NetBeans ● Try to compile and test the project (should work) ● scalaexamples.intro.MyFirstTest – Create a failing test – Make it run ● Make the two classes scalaexamples/intro/HelloWorld.scala print “Hello world”. What is the difference? ● Remove comments from @Test for the methods in scalaexamples/intro/CreateStuffTest.scala. Make tests pass.
  • 36. First class functions val even = Function[Int, Boolean] { def apply(i: Int) = i % 2 == 0 } val even: (Int => Boolean) = (i: Int) => i % 2 == 0 val even = (i: Int) => i % 2 == 0 even.apply(42) // true even(13) // false
  • 37. First class functions val numbers = List(1, 2, 3, 4, 5) numbers.filter(even) // List(2, 4) numbers.filter((i: Int) => i > 2) // List(3, 4, 5) numbers.filter(i => i > 2) // List(3, 4, 5) numbers.filter(_ > 2) // List(3, 4, 5)
  • 38. Collections numbers.filter(i => i > 2) // List(3, 4, 5) numbers.find(i => i > 2) // Some(3) numbers.exists(i => i > 2) // true numbers.forall(i => i > 2) // false numbers.map(i => i * 2) // List(2, 4, 6, 8, 10) numbers.foldLeft(0) { (a, b) => a + b } // 15
  • 39. Closures val people = List(Person(“Alf”), Person(“Fredrik”)) var name = “Fredrik” val nameFilter = (p: Person) => p.name == name people.filter(nameFilter) // Person(“Fredrik”) name = “Alf” people.filter(nameFilter) // Person(“Alf”)
  • 40. Tasks (30 min) ● Open the 'first-class-functions' project ● Tests in package scalaexamples.firstclassfunctions ● Add @Test to one and one method ● Follow instructions in the code ● Make the tests pass
  • 42. myObject match { case 1 => println("First was hit") case 2 => println("Second was Hit") case _ => println("Unknown") }
  • 43. myObject match { case i: Int => println("Found an int") case s: String => println("Found a String") case _ => println("Unknown") }
  • 44. myObject match { case i: Int => println("Found an int") case s: String => println("Found a String") case other => println("Unknown " + other) }
  • 45. myObject match { case i: Int if i == 1 => println("Found an int") case s: String => println("Found a String") case other => println("Unknown " + other) }
  • 46. val res = myObject match { case i: Int if i == 1 => "Found an int" case s: String => "Found a String" case other => "Unknown " + other }
  • 47. val res = myObject match { case (first, second) => second case (first, second, third) => third }
  • 48. val mathedElement = list match { case List(firstElement, lastElement) => lastElement case List(firstElement, _ *) => firstElement case _ => "failed" }
  • 49. def length(list: List[_]): Int = list match { case Nil => 0 case head :: tail => 1 + length(tail) }
  • 50. public static Integer getSecondOr0(List<Integer> list) { if (list != null && list.size() >= 2) { return list.get(1); } else { return 0; } } def second_or_0(list:List[Int]) = list match { case List(_, x, _*) => x case _ => 0 }
  • 51. Case classes ● Class types that can be used in pattern matching ● Generated into your class: ● equals ● hashCode ● toString ● getters (and optionally setters) ● ++
  • 52. abstract class Person(name: String) case class Man(name: String) extends Person(name) case class Woman(name: String, children: List[Person]) extends Person(name)
  • 53. p match { case Man(name) => println("Man with name " + name) case Woman(name, children) => println("Woman with name " + name + " and with " + children.size + " children") }
  • 54. val regex = """(d+)(w+)""".r val myString = ... val res: String = myString match { case regex(digits, word) => digits case _ => "None" }
  • 55. val regex = """(d+)(w+)""".r val myString = ... val res: Option[String] = myString match { case regex(digit, word) => Some(digit) case _ => None }
  • 56. The Option type, never again NullPointerException ● Option has two possible values ● Some(value) ● None val someOption: Option[String] = Some("value") val noOption: Option[String] = None
  • 57. def getValue(s: Any): Option[String] getValue(object) match { case Some(value) => println(value) case None => println("Nothing") } val result = getValue(object).getOrElse("Nothing")
  • 58. Tasks (30 min) ● Open the 'pattern-matching' project ● Tests in package scalaexamples.patternmatching ● Add @Test to one and one method ● Follow instructions in the code ● Make the tests pass
  • 60. Annotations – not marker interfaces @serializable class Person @SerialVersionUID(1) class Person @cloneable class Person @remote class Service
  • 61. object ● object is a “singleton” class ● Call may look like static method calls in Java ● Can inherit from other classes and traits ● Can be passed as a reference object MyObject { def foo = "bar" } var baz = MyObject.foo val personObject = MyObject baz = personObject.foo
  • 62. Companion object ● Can read the companion class' private fields ● Has to be in the same source file class Person(private val age: Int) object Person { def getPersonAge(p: Person) = p.age } val personInstance = new Person(30) val age = Person.getPersonAge(personInstance)
  • 63. Magical apply class Person private(val age: Int) object Person { def apply(age: Int) = new Person(age) } var personInstance = Person.apply(30) personInstance = Person(30)
  • 64. Not built in, clever use of apply val myList = List(1, 2, 3) val mySet = Set(1, 2, 3) val myMap = Map(1 -> "one", 2 -> "two")
  • 65. Constructors ● Always one primary constructor ● Parameters are automatically instance variables ● Class “body” is the primary constructors content ● Auxiliary constructors MUST call or chain to primary constructor class MyClass(myString: String, myInt: Int) val myOtherInt = 10 println("In main body") }
  • 66. Auxiliary constructors class MyClass(myString: String, myInt: Int) { def this(myString: String) = this(myString, 0) def this() = { this("foo") println("In default constructor") } }
  • 67. Inheritance class MyClass(myString: String) class MySubClass(myString: String, myInt: Int) extends MyClass(myString) { println("MyString: '" + myString + "', MyInt: '" + myInt + "'") }
  • 68. Inheritance ● Single class inheritance ● Multiple trait mixins
  • 69. Syntax class Person extends AnyRef with java.io.Serializable with java.rmi.Remote class Person extends java.io.Serializable with java.rmi.Remote
  • 70. Traits ● “Multiple inheritance done right” ● Implement methods ● Initialized fields ● Abstract methods ● Abstract fields ● Abstract types ● Does not have constructors ● Call to super → strict semantics
  • 71. scala.Ordered trait trait Ordered[A] { def compare(that: A): Int def < (that: A): Boolean = (this compare that) < 0 def > (that: A): Boolean = (this compare that) > 0 def <= (that: A): Boolean = (this compare that) <= 0 def >= (that: A): Boolean = (this compare that) >= 0 }
  • 72. The Ordered trait class Person(private val age: Int) extends Ordered[Person] { def compare(other: Person) = this.age - other.age } val person1 = new Person(21) val person2 = new Person(31) person1 < person2 // true person1 <= person2 // true person1 >= person2 // false
  • 73. “Dynamic mixins” class Person(age: Int) { override def toString = "my age is " + age } trait MyTrait { override def toString = "I am sure " + super.toString } val person = new Person(30) with MyTrait println(person) => I am sure my age is 30
  • 74. is-a vs has-a ● Inheritance as usual ● Easier to implement has-a ● Inheritance vs composition
  • 75. Tasks (30 min) ● Open 'oo-traits' project ● Tests under scalaexamples ● companionobject ● inheritance ● traits ● Add @Test to one and one method ● Follow instructions in code ● Make tests pass
  • 77. “Functional programming” ● First class functions ● Pattern matching ● Higher order functions
  • 78. Functional programming ● Purity ● Mathematical functions have no side effects ● f(x) = 2x + 3 ● y = sin(x) ● Mathematical functions always give same result for same input ● Only immutable objects (and object graphs)
  • 79. In practice ● All fields must be immutable ● All methods must return something ● No side-effects from method calls ● println("...") is also a side effect!
  • 80. List ● head :: tail ● Prepends to the head of the list ● Other operations (filter, map, remove, partition...) returns a new List instance
  • 81. scala.collection.immutable ● ...or scala.collection.mutable ● Pick your poison!
  • 82. Scala 2.8 ● Case classes get copy methods ● Constructors and methods get ● named parameters def resize(width: Int, height: Int) = { ... } resize(height = 42, width = 120) ● default parameters def f(elems: List[Int], x: Int = 0, cond: Boolean = true) f(List(1)) f(Nil, cond = false)
  • 83. Strive to be pure ● Parallelization and concurrency (no synchronization) ● Usually easier to find errors (a lot less state) ● Easier to test
  • 84. Refactoring imperative style code def printMultiTable () { var i = 1 // row while (i <= 10) { var j = 1 // column while (j <= 10) { val prod = (i * j).toString var k = prod.length // padding while (k < 4) { 1 2 3 4 5 6 7 8 9 10 print(" ") 2 4 6 8 10 12 14 16 18 20 k += 1 3 6 9 12 15 18 21 24 27 30 } 4 8 12 16 20 24 28 32 36 40 print(prod) 5 10 15 20 25 30 35 40 45 50 j += 1 6 12 18 24 30 36 42 48 54 60 7 14 21 28 35 42 49 56 63 70 } 8 16 24 32 40 48 56 64 72 80 println() 9 18 27 36 45 54 63 72 81 90 i += 1 10 20 30 40 50 60 70 80 90 100 } }
  • 85. Refactoring imperative style code ● Side effect: printing table ● Functional style: return String ● Harder to test ● How to test result of println()? ● While loop & vars ● Functional style: val, for expressions, helper functions ● Helper functions can be tested separately
  • 86. Functional style multiplication table def makeRowSeq(row: Int) = for (col <- 1 to 10) yield { val prod = (row * col).toString val padding = " " * (4 - prod.length) padding + prod } def makeRow(row: Int) = makeRowSeq(row).mkString def multiTable = { val tableSeq = for (row <- 1 to 10) yield makeRow(row) tableSeq.mkString("n") }
  • 87. A closer look at Collections ● Overview of collection traits http://www.decodified.com/scala/collections-api.xml
  • 88. Traversable ● One abstract method: def foreach[U](f: Elem => U) ● 50+ concrete methods ● Addition, mapping, conversion, copying, size info, element retrieval, sub-collection retrieval, subdivision, element tests, folds, string operations, view http://www.scala-lang.org/api/ http://www.scala-lang.org/docu/files/collections-api/
  • 89. Iterable ● Abstract method iterator ● Default implementation of foreach: def foreach[U](f:Elem => U): Unit = { val it = iterator while (it.hasNext) f(it.next()) } ● Subclasses may override ● Some concrete methods ● Subcollections, "zippers", comparison
  • 90. Seq, IndexedSeq, LinearSeq ● Sequence: ● iterable that has a length, ● elements have fixed index position, starting with 0 ● Operations: ● Indexing (apply), search, addition, update, sorting, reversal, comparison, set operations ● IndexedSeq, LinearSeq ● No new operations, but different performance – LinearSeq: efficient head, tail – IndexedSeq: efficient apply, length
  • 91. Sets, SortedSet ● Set = iterable that contain no duplicates ● Operations for tests, addition, removal, set operations ● SortedSet ● Iterator/foreach visit elements in given ordering ● Default implementation: binary tree
  • 92. Maps ● Map = collection of pairs of keys and values e.g. Map("x" -> 24, "y" -> 25, "z" -> 26) ● Operations for lookup, addition/update, removal, subcollections, transformations
  • 96. Higher order functions ● Functions which take functions as parameters and/or return functions
  • 97. Higher order functions Short summary of first class functions: val even: (Int => Boolean) = (i: Int) => i % 2 == 0 Same type definition: def test(numbers: List[Int], f: Int => Boolean) = ... Call: test(List(1, 2, 3), (i: Int) => i % 2 == 0)
  • 98. Higher order functions def test(numbers: List[Int], f: Int => Boolean) = numbers.map(tall => f(tall)) // List[Boolean]
  • 99. Higher order functions Functions with several parameters must list them in parenthesis: def test(l: List[String], f: (Int, String) => Boolean)
  • 100. call-by-value vs. call-by-name ● by-value: expressions are evaluated before being passed to the function ● by-name: expressions evaluated inside function ● nice when computationally expensive ● possible to create nice APIs
  • 101. call-by-value vs. call-by-name Example: Logging def thisTakesTime = { println(“Slow computation”) “result” } logger.debug(thisTakesTime())
  • 102. call-by-value def debug(s: String) { println(“debug”) if (logLevel <= DEBUG) println(s) } // Slow computation // debug // result
  • 103. call-by-name def debug(s: => String) { println(“debug”) if (logLevel <= DEBUG) println(s) } // debug // Slow computation // result
  • 104. BufferedReader reader = null; try { reader = new BufferedReader(new FileReader("f.txt")); System.out.println(reader.readLine()); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { // Exception on close, ignore } } } using(new BufferedReader(new FileReader("f.txt"))) { reader => println(reader.readLine()) }
  • 105. def using[T <: { def close() }, A] (closeable: T) (f: T => A) = { try { f(closeable) } finally { if (closeable != null) { try { closeable.close() } catch { case e: Exception => // Do something clever!? } } } }
  • 106. Tasks (30 min) ● Open 'higher-order-functions' project ● Tests in scalaexamples.higherorderfunctions ● Add @Test to one and one method ● Implement missing functions in PersonFilter and so on. ● Follow instructions in code ● Make tests pass
  • 107. Where to go next?
  • 108. Advanced topics ● Type inference ● Implicit conversions ● Extractors ● Annotations ● XML ● Parallel programming with Actors ● Domain Specific Languages (DSLs) ● GUI programming with Scala Swing
  • 109. Exercises ● Solutions to exercises: http://github.com/javaBin/scala-training-code/zipball/solutions ● 99 Scala Problems: http://aperiodic.net/phil/scala/s-99/
  • 111. A lot of blogs http://www.planetscala.com/
  • 112. Mailing lists scala@listes.epfl.ch scala-announce@listes.epfl.ch scala-user@listes.epfl.ch scala-debate@listes.epfl.ch scala-tools@listes.epfl.ch scala-internals@listes.epfl.ch http://www.scala-lang.org/node/199
  • 113. Several books +++ http://www.scala-lang.org/node/959
  • 114. Creative Commons http://programming-scala.labs.oreilly.com/index.html
  • 116. Creative Commons Attribution 3.0 Unported Scala Training Code http://github.com/javaBin/scala-training-code git clone git://github.com/javaBin/scala-training-code Scala Training Slides http://github.com/javaBin/scala-training-slides git clone git://github.com/javaBin/scala-training-slides.git