What it is and why it rocks<br />Peter Maas<br />2011-Q2<br />
Goals<br />You’ll learn the what & why of Scala<br />You’ll learn what basic Scala programs look like<br />You’ll get an i...
Peter Maas<br />Technical team lead at eBay Classifieds group working at Marktplaats.<br />Interested in programming langu...
Scala<br />ScalableLanguage<br />Statically typed<br />First class citizen on the JVM<br />Multi paradigm: OO, FP<br />
Who uses it<br />
Basic features<br />Immutable value:<br />valname:Type = …<br />Mutable value:<br />varname:Type = …<br />A function:<br /...
Basic control flow<br />If:<br />if(x < 5) doAelsedoB<br />For:<br />for(x <- 0 to 5) println(x)<br />for(x <- 0 to 5) yie...
(Case) Classes<br />Java:<br />publicclass Person {<br />publicfinalString name;<br />publicfinalint age;<br />    Person(...
Collections :: Immutable<br />
Collections :: Mutable<br />
Collections :: Operations<br />Traversing<br />list.foreach( it => println(it) )<br />list.foreach( println(_) )<br />Tran...
Collections :: Operations<br />Grouping<br />	(1 to 10).groupBy(v => v%5) /* Map[Int, Vector[Int]] */<br />Zip<br />List(1...
More concepts<br />Case classes<br />Structural Typing<br />Traits<br />Implicit conversions<br />Operators are functions<...
Structural typing<br />Statically typed version of duck typing<br />Immutable value:<br />deffeed(anyThing: { defeat(f:Foo...
Actors<br />Scalas’ main construct for parallelizing tasks<br />Actors are concurrent processes that communicate by exchan...
Frameworks<br />All existing Java frameworks<br />Database<br />Querulous<br />Casbah<br />Web<br />Play! Scala module<br ...
Note on tools<br />During this presentations you’ve seen SBT, VIM and Intellij Idea in action<br />All major (Java) build ...
More info<br />http://scala-lang.org<br />Programming in Scala 2nd edition (Odersky)<br />twitter.com/p3t0r<br />log4p.com...
Q&a(yes: We are hiring)<br />One more thing:<br />
Upcoming SlideShare
Loading in …5
×

Introduction to Scala for hackersnl gathering

826
-1

Published on

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

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
826
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Introduction to Scala for hackersnl gathering

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

    Clipping is a handy way to collect important slides you want to go back to later.

×