specs2 - scala-syd presentation
DESCRIPTION
This presentation was given to the Scala Sydney user group on Sep. 14th, 2011.TRANSCRIPT
![Page 1: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/1.jpg)
Go functional!
![Page 2: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/2.jpg)
![Page 3: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/3.jpg)
tourimport IncredibleStringReverser._
class ReverserSpec extends Specification { "a reversed empty string must be empty" in { reverse("") must_== "" } "a reversed empty string must really *be empty*" in { reverse("") must be empty } "a reversed string must be reversed abc -> cba" in { reverse("abc") must be_==("cba") } "a longer string must also be reversed. Whoops!" in { reverse("abcdef") must be_==("xxxxx") }}
![Page 4: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/4.jpg)
tour
"a reversed empty string must be empty" in { reverse("") must be empty}
![Page 5: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/5.jpg)
tour
![Page 6: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/6.jpg)
tour
![Page 7: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/7.jpg)
Shame
![Page 8: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/8.jpg)
Mutability
![Page 9: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/9.jpg)
Concurrency
![Page 10: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/10.jpg)
Acceptance
![Page 11: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/11.jpg)
Why
The idea
User
DesignProgram
![Page 12: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/12.jpg)
Go Functional!
But what
is it?!
![Page 13: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/13.jpg)
Referential transparency
Immutabili
ty
![Page 14: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/14.jpg)
behavior
pipelined
FPemerg
entbehavior
Processing data structures
OO
![Page 15: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/15.jpg)
Why
The idea
User
DesignProgram
![Page 16: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/16.jpg)
Starting point
instructions != expressions
![Page 17: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/17.jpg)
Nesting
Precedence:+!^
![Page 18: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/18.jpg)
FormattingText
Example
Text
Example
Example
![Page 19: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/19.jpg)
Formatting
pbrendt, t(i)bt, bt(i)
acceptance
![Page 20: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/20.jpg)
Context
![Page 21: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/21.jpg)
doBefore
withDb.apply(e2)
![Page 22: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/22.jpg)
Why
The idea
User
DesignProgram
![Page 23: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/23.jpg)
Run
execute
levels
select
sequence
arguments
statistics
to text
to html
![Page 24: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/24.jpg)
Laziness vs evaluation
![Page 25: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/25.jpg)
Iterating
![Page 26: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/26.jpg)
Traverse
A datastructure to
traversethe
accumulation
the mapping
![Page 27: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/27.jpg)
Applicative magic?
Lots of instances:• State• List• Monad• Monoid
simple
composable Type inference is hard,Let’s go
shopping!
![Page 28: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/28.jpg)
Reduceraggregation
“parallel” composition
mapping
specs2 reducers:• Levels• Statistics• Arguments• Text• Html
![Page 29: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/29.jpg)
Why
The idea
User
DesignProgram
![Page 30: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/30.jpg)
Trees
Text
Example 1
Example 2
SuiteDescript
ion
Test Descriptio
n 1
Test Descriptio
n 2
SuiteDescription
fChildren = TD1, TD2
![Page 31: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/31.jpg)
TreeLoc
![Page 32: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/32.jpg)
TreeLoc
<h1/>
<h2/> <h2/>
<body>
<h2>part 1</h2><h2>part 2</h2>
<h1>Title 1</h1>
</body>
Anti-XMLThe non-violent solution
![Page 33: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/33.jpg)
Concurrency
a concurrent task
=> Promise[Seq[ExecutedFragment]]
2.9.0
inside!
![Page 34: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/34.jpg)
Exceptions
![Page 35: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/35.jpg)
Exceptions
![Page 36: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/36.jpg)
Exceptions
![Page 37: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/37.jpg)
Mocks
<h1/>
![Page 38: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/38.jpg)
MutabilityBack fo
r
good
Nothing here!
Throws exception
![Page 39: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/39.jpg)
ConfigurationPart of the flow
named parameters + defaults
nested ‘record’
![Page 40: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/40.jpg)
ConfigurationImplicits
implicit arguments
default value
![Page 41: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/41.jpg)
Watch out!
recursivity
SOE
val (a,b) = c
Match
Error
val in traits
NPE
lost expressions
Bug
![Page 42: Specs2 - Scala-Syd presentation](https://reader038.vdocuments.site/reader038/viewer/2022102901/554f62eeb4c905bb178b4896/html5/thumbnails/42.jpg)
Conclusion
• Reliability• Concurrency• Composition• Less mocks• val/vars
• DSL• Type inference• Learning curve• Gotchas