Specs2 - Scala-Syd presentation

1,280 views

Published on

This presentation was given to the Scala Sydney user group on Sep. 14th, 2011.

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

Specs2 - Scala-Syd presentation

  1. 1. 2<br />specs<br />Go functional!<br />
  2. 2. 2<br />specs<br />
  3. 3. tour<br />importIncredibleStringReverser._<br />classReverserSpecextends Specification {<br />"a reversed empty string must be empty" in {<br /> reverse("") must_== ""<br /> }<br />"a reversed empty string must really *be empty*" in {<br /> reverse("") must be empty<br /> }<br />"a reversed string must be reversed abc -> cba" in {<br /> reverse("abc") must be_==("cba")<br /> }<br />"a longer string must also be reversed. Whoops!" in {<br /> reverse("abcdef") must be_==("xxxxx")<br /> }<br />}<br />
  4. 4. tour<br />"a reversed empty string must be empty" in {<br /> reverse("") must be empty<br />}<br />
  5. 5. tour<br />
  6. 6. tour<br />
  7. 7. Shame<br />
  8. 8. Mutability<br />
  9. 9. Concurrency<br />
  10. 10. Acceptance<br />
  11. 11. Why<br />The idea<br />User<br />Program<br />Design<br />
  12. 12. Go Functional!<br />But what is it?!<br />
  13. 13. Referential transparency<br /> Immutability<br />
  14. 14. Processing data structures<br />FP<br />OO<br />pipelined<br />emergent<br />behavior<br />behavior<br />
  15. 15. Why<br />The idea<br />User<br />Program<br />Design<br />
  16. 16. Starting point<br />instructions != expressions<br />
  17. 17. Nesting<br />Precedence:<br />+<br />!<br />^<br />
  18. 18. Formatting<br />Text<br />Example<br />Text<br />Example<br />Example<br />
  19. 19. Formatting<br />p<br />br<br />end<br />t, t(i)<br />bt, bt(i)<br />acceptance<br />
  20. 20. Context<br />
  21. 21. doBefore<br />withDb.apply(e2)<br />
  22. 22. Why<br />The idea<br />User<br />Program<br />Design<br />
  23. 23. Run<br />sequence<br />to text<br />levels<br />to html<br />arguments<br />select<br />statistics<br />execute<br />
  24. 24. Laziness vs evaluation<br />
  25. 25. Iterating<br />
  26. 26. Traverse<br />the mapping<br />A data<br />structure to traverse<br />the accumulation<br />
  27. 27. Applicative magic?<br />simple<br />Lots of instances:<br /><ul><li> State
  28. 28. List
  29. 29. Monad
  30. 30. Monoid</li></ul>Type inference <br />is hard,<br />Let’s go shopping!<br />composable<br />
  31. 31. Reducer<br />aggregation<br />mapping<br />specs2 reducers:<br /><ul><li> Levels
  32. 32. Statistics
  33. 33. Arguments
  34. 34. Text
  35. 35. Html</li></ul>“parallel” composition<br />
  36. 36. Why<br />The idea<br />User<br />Program<br />Design<br />
  37. 37. Trees<br />Suite<br />Description<br />Text<br />Test <br />Description 1<br />Test <br />Description 2<br />Example 1<br />Example 2<br />Suite<br />Description<br />fChildren = TD1, TD2<br />
  38. 38. TreeLoc<br />
  39. 39. TreeLoc<br /><body><br /><h1>Title 1</h1><br /><h2>part 1</h2><br /><h2>part 2</h2><br /><h1/><br /></body><br /><h2/><br /><h2/><br />Anti-XML<br />The non-violent solution<br />
  40. 40. Concurrency<br />=> Promise[Seq[ExecutedFragment]]<br />a concurrent<br /> task<br />2.9.0<br />inside!<br />
  41. 41. Exceptions<br />
  42. 42. Exceptions<br />
  43. 43. Exceptions<br />
  44. 44. Mocks<br /><h1/><br />
  45. 45. Mutability<br />Back for good<br />Nothing here!<br />Throws exception<br />
  46. 46. Configuration<br />Part of the flow<br />nested ‘record’<br />named parameters + defaults<br />
  47. 47. Configuration<br />Implicits<br />default <br />value<br />implicit <br />arguments<br />
  48. 48. Watch out!<br />val in traits<br />recursivity<br />SOE<br />NPE<br />lost expressions<br />val (a,b) = c<br />Bug<br />Match Error<br />
  49. 49. Conclusion<br /><ul><li> Reliability
  50. 50. Concurrency
  51. 51. Composition
  52. 52. Less mocks
  53. 53. val/vars
  54. 54. DSL
  55. 55. Type inference
  56. 56. Learning curve
  57. 57. Gotchas</li>

×