• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Introduction to Scala for hackersnl gathering
 

Introduction to Scala for hackersnl gathering

on

  • 843 views

The deck I used to introduce people to Scala at the hackersnl gathering (http://hackersnl.nl/2011/2011-07-28/)

The deck I used to introduce people to Scala at the hackersnl gathering (http://hackersnl.nl/2011/2011-07-28/)

Statistics

Views

Total Views
843
Views on SlideShare
841
Embed Views
2

Actions

Likes
0
Downloads
5
Comments
0

1 Embed 2

http://www.linkedin.com 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Introduction to Scala for hackersnl gathering Introduction to Scala for hackersnl gathering Presentation Transcript

    • What it is and why it rocks
      Peter Maas
      2011-Q2
    • Goals
      You’ll learn the what & why of Scala
      You’ll learn what basic Scala programs look like
      You’ll get an insight in how deep Scala can be
    • Peter Maas
      Technical team lead at eBay Classifieds group working at Marktplaats.
      Interested in programming languages in general; every new concept you learn might help you solve problems in a smarter / cleaner way.
      Hasn’t worked on a MS Windows machine for quite a while.
      Background in Sound & Music, specialized in pattern recognition. But spend the last decade on web development.
      Might know me from:
      Marktplaats.nl (admarkt)
      VPRO (3voor12, cinema.nl, …)
      Kennis- SURFnet (Video portals, Wikiwijs, Leraar24)
      DBGA (Erfpacht register)
      RaboBank (RaboMobiel)
      Ruby, Clojure, Devnology or DuSeusergroups
      Proud dad of two beautiful kids.
    • Scala
      ScalableLanguage
      Statically typed
      First class citizen on the JVM
      Multi paradigm: OO, FP
    • Who uses it
    • Basic features
      Immutable value:
      valname:Type = …
      Mutable value:
      varname:Type = …
      A function:
      deffunctionName(argName:argType):returnType=/* functionBody */
      Class
      classClassName(constructorArg:argType) { }
      Object:
      object ObjectName { }
      Tuple
      (1,2) or (1,2,"booh",4,5) /* access t._1 , t._3 etc. */
    • Basic control flow
      If:
      if(x < 5) doAelsedoB
      For:
      for(x <- 0 to 5) println(x)
      for(x <- 0 to 5) yield(x * 2) /* returns collections containing x*2 vals */
      for(x <- 0 to 5; y <- 0 to x) yield(x * y) /* comprehensions */
      Pattern Matching:
      something match {
      casea:Int => println(a)
      case (a:Int, b:String) =>
      case x :: xs => /* head, tail */
      case _ =>
      }
    • (Case) Classes
      Java:
      publicclass Person {
      publicfinalString name;
      publicfinalint age;
      Person(String name, int age) {
      this.name = name;
      this.age = age;
      }
      // TODO: implement equals
      // TODO: implement hashCode
      }
      Scala:
      caseclass Person(valname:String, valage:Int)
    • Collections :: Immutable
    • Collections :: Mutable
    • Collections :: Operations
      Traversing
      list.foreach( it => println(it) )
      list.foreach( println(_) )
      Transforming
      list.map( _ * 2)
      urls.par.map(io.Source.fromURL(_).mkString(""))
      Reducing / Folding
      list.reduceLeft(_+_) /* f(f(f(a,b),c),d), f = + */
      list.foldLeft(5)(_+_) /* f(f(f(f(5,a),b),c),d), f = + */
      list.foldRight(List[Int]())((i,l) => if(i%2 == 0) i :: l else l )
      Filtering
      list.filterNot(_%2 == 0)
      Sorting
      list.sorted, list.sortBy(it => it.name)
    • Collections :: Operations
      Grouping
      (1 to 10).groupBy(v => v%5) /* Map[Int, Vector[Int]] */
      Zip
      List(1,2,3,4).zip(List(5,6,7,8)) /* List((1,5), (2,6), (3,7), (4,8)) */
      Much more:
      diff, distinct, exists, grouped, intersect, slice
    • More concepts
      Case classes
      Structural Typing
      Traits
      Implicit conversions
      Operators are functions
      Actors
      Laziness / Streams
    • Structural typing
      Statically typed version of duck typing
      Immutable value:
      deffeed(anyThing: { defeat(f:Food):Unit }) = {
      anyThing.eat(myFood)
      }
      Keeps coupling as low as possible.
    • Actors
      Scalas’ main construct for parallelizing tasks
      Actors are concurrent processes that communicate by exchanging messages
      Akka!
    • Frameworks
      All existing Java frameworks
      Database
      Querulous
      Casbah
      Web
      Play! Scala module
      Lift
      Messaging
      Kafka
      Kestrel
    • Note on tools
      During this presentations you’ve seen SBT, VIM and Intellij Idea in action
      All major (Java) build systems include support (Maven, Ant, Grails, Buildr, SBT)
      Scala IDE (Eclipse based, maintained by TypeSafe)
      Scala plugin for Intellij IDEA
      Scala plugin for NetBeans
      And yes… it’s not 100% on par with tooling Java people are generally used to; but still good enough to work in a comfortable way.
    • More info
      http://scala-lang.org
      Programming in Scala 2nd edition (Odersky)
      twitter.com/p3t0r
      log4p.com
    • Q&a(yes: We are hiring)
      One more thing: