SlideShare a Scribd company logo
DR.
SCALA
LOVE
Dianne Marsh
Director of Engineering -- Cloud Tools, Netflix
ScalaBay Meetup, Sept 2013
OR
HOW
I
LEARNED
TO
STOP
WORRYING
AND
LOVE
FUNCTIONS
Dr. Strangelove, 1964
“If this thing turns out
to be half as important
as I think it will be, I
think you’ll all be in
line for some personal
citations and
promotions when this
thing is over.”
What is Scala?
Object-oriented + Functional
Runs on JVM
Build on Java expertise
Why Is it Scary?
Early adopters scared folks away
Lost elasticity of learning new programming
languages
Comfort zone
What’s the Gain?
Modern language features
Let compiler work for you!
REPL
Interactive Interpreter
Read Evaluate Print Loop
Type Inference
val x = 5
val y = "Once upon a time"
val l = List("This", "is", "a",
"List")
Methods
def squareIt(x: Int) = x*x
Anatomy of a Case Class
case class Camera(width: Int,
height: Int) {
def megapixels = (width * height)
/1000000.0
def HD = megapixels > 1.08
}
val camera = new Camera(1024, 768)
camera.megapixels is 0.786432
camera.HD is false
camera is "Camera(1024,768)"
Reducing Boilerplate
class Dimension(var height:Int,
var width:Int)
val c = new Dimension(5,7)
c.height is 5
c.height = 10
c.height is 10
c.width = 19
c.width is 19
Pattern Matching
def batteryIndicator(batteryLevel:
Int) =
batteryLevel match {
case l if (l > 60) => "GREEN"
case l if (l > 20) => "YELLOW"
case _ => "RED"
}
Traits
trait Digital {
def batteryIndicator(batteryLevel:
Int) = …
}
val d = new Camera(1024, 768) with
Digital
d.batteryIndicator(56) is "YELLOW"
Functions are Objects
val v = Vector(19, 1, 7, 3, 2, 14)
v.sorted is Vector(1, 2, 3, 7, 14, 19)
v.sortWith((i, j) => j < i) is
Vector(19, 14, 7, 3, 2, 1)
It’s OK
To use Scala as a Better Java
Reaching into Java
import org.apache.commons.math._
import stat.regression.SimpleRegression
val r = new SimpleRegression
r.addData(1, 1)
r.addData(2, 1.1)
r.addData(3, 0.9)
r.addData(4, 1.2)
r.getN is 4
r.predict(6) is 1.19
It’s OK
To be verbose
Verbose Version
// Euler1.scala
val nums = 3 until 1000
val somenums = nums.filter
(x => (x % 3 == 0 || x % 5 ==0))
var sum = 0
somenums.foreach(sum += _)
Find the Sweet Spot
// Euler2.scala
val nums = 3 until 1000
val somenums = nums filter
(x => (x % 3 == 0 || x % 5 ==0))
val sum = somenums reduceLeft
{(x:Int,y:Int) => x + y}
More than 1 way ...
// Euler3.scala
val nums = 3 until 1000
val somenums = nums filter
(x => (x % 3 == 0 || x % 5 ==0))
val sum = somenums.foldLeft(0)(_+_)
Back off if it’s too much
// Euler4.scala
val nums = 3 until 1000
val somenums = nums filter
(x => (x % 3 == 0 || x % 5 ==0))
(0/:somenums)(_+_)
Code should be readable
To your team
To your customers
To yourself, in 6 months
Killer Apps in Scala
Compute intensive
Concurrency
Reactive applications
● Resilient
● Scalable
● Interactive, single-page
● Event Driven
Learning
Scala Koans -- scalakoans.org
Case Studies at Typesafe
Blogs
Books
Practicing
Solve Euler problems
Use ScalaTest
Use for non-production code
Contact Info
@dmarsh
dmarsh@netflix.com
We are always hiring ...

More Related Content

PPTX
Scala Introduction
PDF
Scala parallel-collections
PPTX
Functional linear data structures in f#
PPT
L11 array list
PDF
Java 8 - An Introduction by Jason Swartz
PPTX
Array vs array list
PDF
ScalaDays 2015 Keynote
PDF
Walking the Tightrope: Balancing Bias to Action and Planning
Scala Introduction
Scala parallel-collections
Functional linear data structures in f#
L11 array list
Java 8 - An Introduction by Jason Swartz
Array vs array list
ScalaDays 2015 Keynote
Walking the Tightrope: Balancing Bias to Action and Planning

Similar to Dr scalalove: How I learned to stop worrying and love the functions (20)

PDF
Scala Quick Introduction
PDF
Meet scala
PDF
Power of functions in a typed world
ODP
Functional programming with Scala
PDF
Introduction à Scala - Michel Schinz - January 2010
PPTX
PDF
From Java to Scala - advantages and possible risks
ODP
Functional Programming With Scala
PDF
Sequence and Traverse - Part 3
PDF
Types Working for You, Not Against You
PPTX
PDF
Introduction To Scala
PDF
Functional Programming in Scala
PDF
Beyond xUnit example-based testing: property-based testing with ScalaCheck
PPTX
Scala for curious
PDF
Scala Intro
PPTX
Intro to Functional Programming in Scala
PDF
Demystifying Scala
PDF
Scala cheatsheet
PPTX
Scala fundamentals
Scala Quick Introduction
Meet scala
Power of functions in a typed world
Functional programming with Scala
Introduction à Scala - Michel Schinz - January 2010
From Java to Scala - advantages and possible risks
Functional Programming With Scala
Sequence and Traverse - Part 3
Types Working for You, Not Against You
Introduction To Scala
Functional Programming in Scala
Beyond xUnit example-based testing: property-based testing with ScalaCheck
Scala for curious
Scala Intro
Intro to Functional Programming in Scala
Demystifying Scala
Scala cheatsheet
Scala fundamentals
Ad

More from Dianne Marsh (11)

PDF
KubeCon/Cloud Native Keynote December 2017
PDF
Velocity 2017 Keynote: Looking Back to Move Forward
PDF
OSS Collaboration & Contribution: How Netflix Drives Industry Engagement
PDF
The Paved Road at Netflix
PDF
How Netflix thinks of DevOps. Spoiler: we don’t.
PDF
Introducing Change while Preserving Engineering Velocity
PDF
Engineering Velocity: Shifting the Curve at Netflix
PDF
Saturn 2014. Engineering Velocity: Continuous Delivery at Netflix
PPTX
Open Business Conference: Continuous Delivery At Netflix -- Powered by Open S...
PPTX
From Code to the Monkeys: Continuous Delivery at Netflix
PPT
Sneaking Scala through the Back Door
KubeCon/Cloud Native Keynote December 2017
Velocity 2017 Keynote: Looking Back to Move Forward
OSS Collaboration & Contribution: How Netflix Drives Industry Engagement
The Paved Road at Netflix
How Netflix thinks of DevOps. Spoiler: we don’t.
Introducing Change while Preserving Engineering Velocity
Engineering Velocity: Shifting the Curve at Netflix
Saturn 2014. Engineering Velocity: Continuous Delivery at Netflix
Open Business Conference: Continuous Delivery At Netflix -- Powered by Open S...
From Code to the Monkeys: Continuous Delivery at Netflix
Sneaking Scala through the Back Door
Ad

Recently uploaded (20)

PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
Encapsulation theory and applications.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
Machine Learning_overview_presentation.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Tartificialntelligence_presentation.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
August Patch Tuesday
PDF
Getting Started with Data Integration: FME Form 101
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
A Presentation on Artificial Intelligence
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Mushroom cultivation and it's methods.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Empathic Computing: Creating Shared Understanding
cloud_computing_Infrastucture_as_cloud_p
Encapsulation theory and applications.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Machine Learning_overview_presentation.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Tartificialntelligence_presentation.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Assigned Numbers - 2025 - Bluetooth® Document
Per capita expenditure prediction using model stacking based on satellite ima...
SOPHOS-XG Firewall Administrator PPT.pptx
August Patch Tuesday
Getting Started with Data Integration: FME Form 101
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Machine learning based COVID-19 study performance prediction
A Presentation on Artificial Intelligence
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Mushroom cultivation and it's methods.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Empathic Computing: Creating Shared Understanding

Dr scalalove: How I learned to stop worrying and love the functions