Successfully reported this slideshow.

BRUG - Hello, Scala

851 views

Published on

Introduction to functional programming for the Bristol Ruby User Group

Published in: Technology
  • Be the first to comment

BRUG - Hello, Scala

  1. 1. Hello, Scala Timothy Perrett BRUG, October 2011 software. done right.
  2. 2. About Me Author of Lift in Action Coding Scala since 2007 (its awesome) Background in both dynamic and statically typed languages Manufacturing and marketing automation is my day job http://manning.com/perrett/ software. done right.
  3. 3. Scalais…software. done right.
  4. 4. A statically typed, hybrid object-functional programming language software. done right.
  5. 5. functional programming is... software. done right.
  6. 6. …programming with functions software. done right.
  7. 7. A program is software. done right.
  8. 8. a single, referentially transparent expression software. done right.
  9. 9. An expression is software. done right.
  10. 10. a combination of sub expressions,using the constructs of a language. It evaluates to a result. software. done right.
  11. 11. a referentially transparent expression... software. done right.
  12. 12. …is an expression that can be replaced directly by its result without affecting the program operation. i.e. no side-effects software. done right.
  13. 13. a side-effect is... software. done right.
  14. 14. for example:  I/O  variable mutation throwing exceptions software. done right.
  15. 15. a function is... software. done right.
  16. 16. a relation between every value of type A to exactly one value of type B. (given f: A => B) software. done right.
  17. 17. functional programming gives you… software. done right.
  18. 18. modularity and compositionality software. done right.
  19. 19. fpis a style, not a language software. done right.
  20. 20. and static typing?... software. done right.
  21. 21. well, ruby is… software. done right.
  22. 22. duck typed… software. done right.
  23. 23. …scala is statically typed software. done right.
  24. 24. ”…types save you from errors, give you usefulprogram documentation and act as a safety net forrefactoring…" Martin Odersky software. done right.
  25. 25. code samples software. done right.
  26. 26. nums = [1,2,3,4]nums.select do |n|n % 2 == 0end software. done right.
  27. 27. valnums = Seq(1,2,3,4)nums.filter { n =>n % 2 == 0} software. done right.
  28. 28. valnums = Seq(1,2,3,4)nums.filter(_ % 2 == 0) software. done right.
  29. 29. useful data types software. done right.
  30. 30. valfoo = Option("thing")//=>Some(“thing”)val bar = Option(null)//=> None software. done right.
  31. 31. foo = … // comes from user inputif foo == nil then // do something with fooend software. done right.
  32. 32. // where foo is user inputOption(foo).map(x => …) software. done right.
  33. 33. implicit pimps software. done right.
  34. 34. class Foo(word: String) { def say = println(word)}implicit def strToFoo(in: String): Foo …“word”.say software. done right.
  35. 35. supports DSLs… software. done right.
  36. 36. take 2 pills and call me in the morningtake(2.pills).and(call).me(in).the(morning) software. done right.
  37. 37. blistering performance software. done right.
  38. 38. Performance 60 50 40 30 Scala Ruby (Jruby) Ruby 1.9 20 10 0 Scala Ruby (Jruby) Ruby 1.9source: http://shootout.alioth.debian.org/ software. done right.
  39. 39. heaps more awesome  Concurrency abstractions  Parallel data structures  BDD & property testing  Ad-hoc polymorphism  Higher-kinded types  Existential types software. done right.
  40. 40. Questions?twitter.com/timperrett Lift in Actiongithub.com/timperrett manning.com/perrett/blog.getintheloop.eu software. done right.

×