Video and slides synchronized, mp3 and slide download available at URL http://bit.ly/1ZW7TDL.
Richard Dallaway shows an example of what Scala looks like when using pattern matching over classes, how to encode an idea into types and use advanced features of Scala without complicating the code. Filmed at qconlondon.com.
Richard Dallaway is a partner at Underscore -- a consultancy specializing in Scala, especially the type-driven and functional aspects of Scala. He works on client projects writing software and helping teams deliver software with Scala. His focus is on the web, machine learning, and code review. He's the co-author of "Essential Slick" (Underscore), and author of the "Lift Cookbook" (O'Reilly).
2. InfoQ.com: News & Community Site
• 750,000 unique visitors/month
• Published in 4 languages (English, Chinese, Japanese and Brazilian
Portuguese)
• Post content from our QCon conferences
• News 15-20 / week
• Articles 3-4 / week
• Presentations (videos) 12-15 / week
• Interviews 2-3 / week
• Books 1 / month
Watch the video with slide
synchronization on InfoQ.com!
http://www.infoq.com/presentations
/scala-patterns-types
3. Purpose of QCon
- to empower software development by facilitating the spread of
knowledge and innovation
Strategy
- practitioner-driven conference designed for YOU: influencers of
change and innovation in your teams
- speakers and topics driving the evolution and innovation
- connecting and catalyzing the influencers and innovators
Highlights
- attended by more than 12,000 delegates since 2007
- held in 9 cities worldwide
Presented at QCon London
www.qconlondon.com
10. The only problem was we had no idea what the code
was doing at first.
We came across a strange symbol we hadn’t seen in
our projects before
The spaceship operator <|*|>
Someone said out loud “what the hell is that?”
http://jimplush.com/talk/
11. The only problem was we had no idea what the code
was doing at first.
We came across a strange symbol we hadn’t seen in
our projects before
The spaceship operator <|*|>
Someone said out loud “what the hell is that?”
http://jimplush.com/talk/
12. The only problem was we had no idea what the code
was doing at first.
We came across a strange symbol we hadn’t seen in
our projects before
The spaceship operator <|*|>
Someone said out loud “what the hell is that?”
http://jimplush.com/talk/
13. The only problem was we had no idea what the code
was doing at first.
We came across a strange symbol we hadn’t seen in
our projects before
The spaceship operator <|*|>
Someone said out loud “what the hell is that?”
http://jimplush.com/talk/
14. “It’s about having a maintainable
code base where you can have
people cross projects easily and
get new hires up to speed rapidly”
35. def serveAd(v: Visitor): Advert =
v match {
case User(_, info) => relevantAd(info)
case Anonymous(id) => adRotation(id)
}
36. def serveAd(v: Visitor): Advert =
v match {
case User(_, info) => relevantAd(info)
case Anonymous(id) => adRotation(id)
}
37. def serveAd(v: Visitor): Advert =
v match {
case User(_, info) => relevantAd(info)
case Anonymous(id) => adRotation(id)
}
Structure
38. ADT & Structural Recursion
Straightforward part of Scala.
Clear, productive, occurs frequently.
Be opinionated in what you use.
Structure helps us.
40. Combining lists
Concatenating strings
Union of sets
Combining things in a loop
Chaining logical operations
Adding numbers
Building up a JavaScript expression
Showing errors in a UI
...
60. def fold(vs: List[Int]): Int =
vs match {
case Nil => 0
case v :: rest => v + fold(rest)
}
fold(List(1,2,3))
// 6
61. def fold(vs: List[Int], m: Monoid[Int]): Int =
vs match {
case Nil => 0
case v :: rest => v + fold(rest)
}
fold(List(1,2,3), addition)
// 6
62. def fold(vs: List[Int], m: Monoid[Int]): Int =
vs match {
case Nil => m.empty
case v :: rest => m.combine(v, fold(rest,m))
}
fold(List(1,2,3), addition)
// 6
63. def fold[T](vs: List[T], m: Monoid[T]): T =
vs match {
case Nil => m.empty
case v :: rest => m.combine(v, fold(rest,m))
}
fold(List(1,2,3), addition)
// 6
106. case class User(
id : Long,
name : String,
email : Option[String])
case class Update(
name : Option[String],
email : Option[Option[String]])
107. val user = User(
123L,
“Bruce Wayne”,
Some(“bruce@example.org”))
val update = Update(
Some(“Batman”),
None)
How do we get to…
User(
123L,
“Batman”,
Some(“bruce@example.org”))
119. 2008
‘The name Scala stands for
“scalable language.”
The language is so named
because it was designed
to grow with the demands of its
users.’
120. What have we seen?
Some straightforward parts of Scala
—Clear, maintainable, helpful
Encoding ideas in types
—flexibility, leads us to solutions
Let the compiler do it
—when it make sense for your demands
121. Summary
Scala scaling with your needs
—be opinionated in what you use, more when needed
Types working for us, not stopping us
—functional programming, share what you learn