SlideShare a Scribd company logo
1 of 132
Download to read offline
Programming with Scala
Brian Topping
Mauswerks LLC
About Me
• Globally experienced dev with over 25 years professional experience
• Have led teams of three to fifteen developers as lead developer,
architect, general manager. Start projects first, then hire when ten
fingers are not enough.
• Have been using Scala since 2012, JDK Open Source since 2001
• Interests: Functional Reactive Programming, financial markets,
machine learning, Javascript, travel, motorcycles
• Shameless plug: Available for investment or work in BKK
• http://github.com/briantopping

http://twitter.com/briantopping

http://linkedin.com/in/briantopping
Why Scala?
What is wrong with this picture?
• "Looks good to me, ship it!"
• "Looks good to me, ship it!"
• We're at the wrong level of zoom to see problems

• "Looks good to me, ship it!"
• We're at the wrong level of zoom to see problems

• 

• "Looks good to me, ship it!"
• We're at the wrong level of zoom to see problems

• 

• Solutions at a global level must factor problems at the
local level.
• "Looks good to me, ship it!"
• We're at the wrong level of zoom to see problems

• 

• Solutions at a global level must factor problems at the
local level.
• Complexity is the natural tradeoff
What is Scala?
• Object Oriented / Functional hybrid
• Compiled to JVM bytecode
• Statically typed (compile time)
• Strongly typed (types must match)
• Growing ecosystem
• Language is stable and mature
(a few) Benefits of Scala
• Seamless Java / JDK ecosystem interoperability
• Type Inferencing & Parameterization
• Concurrency & Distribution
• Collections Classes
• Pattern Matching
• Obvious Correctness
Standard Example
Standard Example
• Java "Bean"















Standard Example
• Java "Bean"















Standard Example
• Java "Bean"















• Scala Case Class
Standard Example
• Java "Bean"















• Scala Case Class
Standard Example
• Java "Bean"















• Scala Case Class
Java / JDK Interoperability
Java / JDK Interoperability
• Scala classes are JVM classes
Java / JDK Interoperability
• Scala classes are JVM classes
• Groovy, Clojure, JRuby, Jython – 40+ in all!
Java / JDK Interoperability
• Scala classes are JVM classes
• Groovy, Clojure, JRuby, Jython – 40+ in all!
• Scala is a mixed Object + Functional language
Java / JDK Interoperability
• Scala classes are JVM classes
• Groovy, Clojure, JRuby, Jython – 40+ in all!
• Scala is a mixed Object + Functional language
• It is possible and common for young teams to start
writing Scala with Java style (OOD) and API, test
with existing tools
Java / JDK Interoperability
• Scala classes are JVM classes
• Groovy, Clojure, JRuby, Jython – 40+ in all!
• Scala is a mixed Object + Functional language
• It is possible and common for young teams to start
writing Scala with Java style (OOD) and API, test
with existing tools
• Take advantage of Java libraries
Java / JDK Interoperability
• Scala classes are JVM classes
• Groovy, Clojure, JRuby, Jython – 40+ in all!
• Scala is a mixed Object + Functional language
• It is possible and common for young teams to start
writing Scala with Java style (OOD) and API, test
with existing tools
• Take advantage of Java libraries
Type Inference &
Immutability Focus
Type Inference &
Immutability Focus
• Compiler knows the type of an assignment, yet most
languages require the developer to prove it
Type Inference &
Immutability Focus
• Compiler knows the type of an assignment, yet most
languages require the developer to prove it
• Java:
Type Inference &
Immutability Focus
• Compiler knows the type of an assignment, yet most
languages require the developer to prove it
• Java:
• Scala:
Type Inference &
Immutability Focus
• Compiler knows the type of an assignment, yet most
languages require the developer to prove it
• Java:
• Scala:
• Built for immutability!
Type Inference &
Immutability Focus
• Compiler knows the type of an assignment, yet most
languages require the developer to prove it
• Java:
• Scala:
• Built for immutability!
• Use the var keyword for mutable variables
Type Inference &
Immutability Focus
• Compiler knows the type of an assignment, yet most
languages require the developer to prove it
• Java:
• Scala:
• Built for immutability!
• Use the var keyword for mutable variables
• One finds themselves using it less and less often!
Type Parameterization
Type Parameterization
• Types allow you to denote function domain & codomains. For example, from
mathematics, we are used to seeing:





this tells us that function “f” maps values from the set of real numbers to values
of the set of natural numbers
Type Parameterization
• Types allow you to denote function domain & codomains. For example, from
mathematics, we are used to seeing:





this tells us that function “f” maps values from the set of real numbers to values
of the set of natural numbers
• In the abstract, this is exactly what concrete types are. Type systems give us
some more powerful ways to express these sets
Type Parameterization
• Types allow you to denote function domain & codomains. For example, from
mathematics, we are used to seeing:





this tells us that function “f” maps values from the set of real numbers to values
of the set of natural numbers
• In the abstract, this is exactly what concrete types are. Type systems give us
some more powerful ways to express these sets
• Given these annotations, the compiler can now statically (at compile time) verify
that the program is sound
Type Parameterization
• Types allow you to denote function domain & codomains. For example, from
mathematics, we are used to seeing:





this tells us that function “f” maps values from the set of real numbers to values
of the set of natural numbers
• In the abstract, this is exactly what concrete types are. Type systems give us
some more powerful ways to express these sets
• Given these annotations, the compiler can now statically (at compile time) verify
that the program is sound
• Variance annotations allow you to express relationships between class
hierarchies & polymorphic types
Type Parameterization
• Types allow you to denote function domain & codomains. For example, from
mathematics, we are used to seeing:





this tells us that function “f” maps values from the set of real numbers to values
of the set of natural numbers
• In the abstract, this is exactly what concrete types are. Type systems give us
some more powerful ways to express these sets
• Given these annotations, the compiler can now statically (at compile time) verify
that the program is sound
• Variance annotations allow you to express relationships between class
hierarchies & polymorphic types
• Reference: http://twitter.github.io/scala_school/type-basics.html
Concurrency & Distribution
Concurrency & Distribution
• Futures and Promises – Long history across platforms
Concurrency & Distribution
• Futures and Promises – Long history across platforms
• Factory objects look like integral part of language
Concurrency & Distribution
• Futures and Promises – Long history across platforms
• Factory objects look like integral part of language
• Remember that functions are parameters!
Concurrency & Distribution
• Futures and Promises – Long history across platforms
• Factory objects look like integral part of language
• Remember that functions are parameters!
• 

Concurrency & Distribution
• Futures and Promises – Long history across platforms
• Factory objects look like integral part of language
• Remember that functions are parameters!
• 

• Don't return values, return a Future!
Concurrency & Distribution
• Futures and Promises – Long history across platforms
• Factory objects look like integral part of language
• Remember that functions are parameters!
• 

• Don't return values, return a Future!
• Akka-HTTP is a perfect example, you can return a value, but then your
code manages the concurrency. Return a Future to the caller and let it
manage it instead!
Concurrency & Distribution
• Futures and Promises – Long history across platforms
• Factory objects look like integral part of language
• Remember that functions are parameters!
• 

• Don't return values, return a Future!
• Akka-HTTP is a perfect example, you can return a value, but then your
code manages the concurrency. Return a Future to the caller and let it
manage it instead!
• Unlike Node, full access to all cores.
Collections Classes
Collections Classes
• Scala Collections are what brought me to the language
Collections Classes
• Scala Collections are what brought me to the language
• Designed to consistently behave as a collections DSL
Collections Classes
• Scala Collections are what brought me to the language
• Designed to consistently behave as a collections DSL
• Immutable by default, great for parallel deployments
Collections Classes
• Scala Collections are what brought me to the language
• Designed to consistently behave as a collections DSL
• Immutable by default, great for parallel deployments
• Java
Collections Classes
• Scala Collections are what brought me to the language
• Designed to consistently behave as a collections DSL
• Immutable by default, great for parallel deployments
• Java
•
Collections Classes
• Scala Collections are what brought me to the language
• Designed to consistently behave as a collections DSL
• Immutable by default, great for parallel deployments
• Java
•
• Scala
Collections Classes
• Scala Collections are what brought me to the language
• Designed to consistently behave as a collections DSL
• Immutable by default, great for parallel deployments
• Java
•
• Scala
•
Collections Classes
• Scala Collections are what brought me to the language
• Designed to consistently behave as a collections DSL
• Immutable by default, great for parallel deployments
• Java
•
• Scala
•
• Don't get the wrong idea here! Rolling a one-liner into a println is not what I'd call
"good style". Instead, note how the functional transparency and type inferencing
allows us to inline functions as easily as we can assign them to variables.
Pattern Matching
Pattern Matching
• Partial Functions – A function that is only defined for
specific input values 

Pattern Matching
• Partial Functions – A function that is only defined for
specific input values 

• 

Pattern Matching
• Partial Functions – A function that is only defined for
specific input values 

• 

• Regular Expressions – Please enjoy them now! 😉
Pattern Matching
• Partial Functions – A function that is only defined for
specific input values 

• 

• Regular Expressions – Please enjoy them now! 😉
•
Obvious Correctness
Obvious Correctness
• Trick question: Which of these is more obviously correct?





Obvious Correctness
• Trick question: Which of these is more obviously correct?





• Java:







Obvious Correctness
• Trick question: Which of these is more obviously correct?





• Java:







• Scala:
Obvious Correctness
• Trick question: Which of these is more obviously correct?





• Java:







• Scala:
• Depends on experience!!
Team Evolution w/ Scala
Team Evolution w/ Scala
• Start with this:







Team Evolution w/ Scala
• Start with this:







• To get to this:

Team Evolution w/ Scala
• Start with this:







• To get to this:

• Make the transition gradually! Do it together as a team!
What does all this buy us?
What does all this buy us?
• Pure functions have no side effects... data in, data out
What does all this buy us?
• Pure functions have no side effects... data in, data out
• Objects maintain state. This is why Scala is not
considered a purely functional language!
What does all this buy us?
• Pure functions have no side effects... data in, data out
• Objects maintain state. This is why Scala is not
considered a purely functional language!
• When objects are immutable though, the state acts as
constants in the functions. Constants are thread-safe!
What does all this buy us?
• Pure functions have no side effects... data in, data out
• Objects maintain state. This is why Scala is not
considered a purely functional language!
• When objects are immutable though, the state acts as
constants in the functions. Constants are thread-safe!
• Immutable objects do not need to be locked. Locking is
actually very expensive and error prone
What does all this buy us?
• Pure functions have no side effects... data in, data out
• Objects maintain state. This is why Scala is not
considered a purely functional language!
• When objects are immutable though, the state acts as
constants in the functions. Constants are thread-safe!
• Immutable objects do not need to be locked. Locking is
actually very expensive and error prone
• Immutable state is updated by replacing the object!
But it looks so complex!
But it looks so complex!
• Scala actually has a smaller grammar than Java
But it looks so complex!
• Scala actually has a smaller grammar than Java
• Functional composition (the ability for one function to feed
another) allows intermediate variables to be removed.
But it looks so complex!
• Scala actually has a smaller grammar than Java
• Functional composition (the ability for one function to feed
another) allows intermediate variables to be removed.
• Scala ends up looking complex because developers collapse
code that maybe shouldn't be collapsed.
But it looks so complex!
• Scala actually has a smaller grammar than Java
• Functional composition (the ability for one function to feed
another) allows intermediate variables to be removed.
• Scala ends up looking complex because developers collapse
code that maybe shouldn't be collapsed.
• Program so your code is readable, not so it fits in as few
lines as possible.
But it looks so complex!
• Scala actually has a smaller grammar than Java
• Functional composition (the ability for one function to feed
another) allows intermediate variables to be removed.
• Scala ends up looking complex because developers collapse
code that maybe shouldn't be collapsed.
• Program so your code is readable, not so it fits in as few
lines as possible.
• Occam's Razor: We should reduce to the simplest possible
outcome, and no simpler!
Some things haven't changed
Some things haven't changed
• TDD – Use it! Create unit tests for everything, use them as documentation
Some things haven't changed
• TDD – Use it! Create unit tests for everything, use them as documentation
• One liners should have a simple comment describing what they do 

Some things haven't changed
• TDD – Use it! Create unit tests for everything, use them as documentation
• One liners should have a simple comment describing what they do 

• Frequent code reviews! Pull requests that receive no comments are to be
avoided.
Some things haven't changed
• TDD – Use it! Create unit tests for everything, use them as documentation
• One liners should have a simple comment describing what they do 

• Frequent code reviews! Pull requests that receive no comments are to be
avoided.
• Avoid learning a new technique and immediately using it everywhere.
Some things haven't changed
• TDD – Use it! Create unit tests for everything, use them as documentation
• One liners should have a simple comment describing what they do 

• Frequent code reviews! Pull requests that receive no comments are to be
avoided.
• Avoid learning a new technique and immediately using it everywhere.
• If you are the only person that can maintain your code, you will be cursed
to own it forever.
Some things haven't changed
• TDD – Use it! Create unit tests for everything, use them as documentation
• One liners should have a simple comment describing what they do 

• Frequent code reviews! Pull requests that receive no comments are to be
avoided.
• Avoid learning a new technique and immediately using it everywhere.
• If you are the only person that can maintain your code, you will be cursed
to own it forever.
• If you can inspire others to read your code because it is both short and
people "learn one new thing" (only one!), you will be able to move the team
forward with new techniques, do more with less, have fun!
I'm not sold yet...
I'm not sold yet...
• Take Coursera's Scala class taught by Martin Odersky
I'm not sold yet...
• Take Coursera's Scala class taught by Martin Odersky
• You will become a better Scala programmer
I'm not sold yet...
• Take Coursera's Scala class taught by Martin Odersky
• You will become a better Scala programmer
• You will become a better Java programmer
I'm not sold yet...
• Take Coursera's Scala class taught by Martin Odersky
• You will become a better Scala programmer
• You will become a better Java programmer
• You will become a better programmer
I'm not sold yet...
• Take Coursera's Scala class taught by Martin Odersky
• You will become a better Scala programmer
• You will become a better Java programmer
• You will become a better programmer
• Apple's Swift language is a bit of a knockoff
I'm not sold yet...
• Take Coursera's Scala class taught by Martin Odersky
• You will become a better Scala programmer
• You will become a better Java programmer
• You will become a better programmer
• Apple's Swift language is a bit of a knockoff
• Get two platforms for the price of one!
How Do I Get Started?
IDEs: IntelliJ vs. Eclipse
IDEs: IntelliJ vs. Eclipse
IDEs: IntelliJ vs. Eclipse
IDEs: IntelliJ vs. Eclipse
• They both have advantages. Each team should "bake off" and doc the results
IDEs: IntelliJ vs. Eclipse
• They both have advantages. Each team should "bake off" and doc the results
• Don't be restricted to one, but a common denominator of skills is helpful         
Testing
Testing
• ScalaTest is standard
Testing
• ScalaTest is standard
• Behavior Driven Development
Testing
• ScalaTest is standard
• Behavior Driven Development
• Use with TDD, just works!
Testing
• ScalaTest is standard
• Behavior Driven Development
• Use with TDD, just works!
• The power is in the Matchers











Development Environments
Development Environments
• REPL (Read-Eval-Print Loop) is an interactive shell
Development Environments
• REPL (Read-Eval-Print Loop) is an interactive shell
• scalac compiler can be run from command line like javac
Development Environments
• REPL (Read-Eval-Print Loop) is an interactive shell
• scalac compiler can be run from command line like javac
• SBT is Scala's own build tool, allows Scala code to be used within build, but not
very IDE friendly.
Development Environments
• REPL (Read-Eval-Print Loop) is an interactive shell
• scalac compiler can be run from command line like javac
• SBT is Scala's own build tool, allows Scala code to be used within build, but not
very IDE friendly.
• Maven has a Scala plugin, but comes with all of Maven's idiosyncrasies.
Development Environments
• REPL (Read-Eval-Print Loop) is an interactive shell
• scalac compiler can be run from command line like javac
• SBT is Scala's own build tool, allows Scala code to be used within build, but not
very IDE friendly.
• Maven has a Scala plugin, but comes with all of Maven's idiosyncrasies.
• SBT can use Maven central repository, but is designed for Ivy repositories. Both
end up being required, which is a pain point.
Development Environments
• REPL (Read-Eval-Print Loop) is an interactive shell
• scalac compiler can be run from command line like javac
• SBT is Scala's own build tool, allows Scala code to be used within build, but not
very IDE friendly.
• Maven has a Scala plugin, but comes with all of Maven's idiosyncrasies.
• SBT can use Maven central repository, but is designed for Ivy repositories. Both
end up being required, which is a pain point.
• All the cool kids use SBT, but it's not as mature and harder to use with projects
that span multiple source repositories, also not as simple for tagged release
environments.
Development Environments
• REPL (Read-Eval-Print Loop) is an interactive shell
• scalac compiler can be run from command line like javac
• SBT is Scala's own build tool, allows Scala code to be used within build, but not
very IDE friendly.
• Maven has a Scala plugin, but comes with all of Maven's idiosyncrasies.
• SBT can use Maven central repository, but is designed for Ivy repositories. Both
end up being required, which is a pain point.
• All the cool kids use SBT, but it's not as mature and harder to use with projects
that span multiple source repositories, also not as simple for tagged release
environments.
• Verdict: If you already use Maven, stick with it, otherwise use SBT.
Concurrency & Distribution
Part 2
Concurrency & Distribution
Part 2
• Use Akka – http://akka.io
Concurrency & Distribution
Part 2
• Use Akka – http://akka.io
• Scala and Java APIs, Scala easier to use via immutables
Concurrency & Distribution
Part 2
• Use Akka – http://akka.io
• Scala and Java APIs, Scala easier to use via immutables
• Message passing pattern without all the JMS overhead
Concurrency & Distribution
Part 2
• Use Akka – http://akka.io
• Scala and Java APIs, Scala easier to use via immutables
• Message passing pattern without all the JMS overhead
• 50 million msg/sec on a single machine + small memory footprint; ~2.5
million actors (message endpoints) per GB of heap
Concurrency & Distribution
Part 2
• Use Akka – http://akka.io
• Scala and Java APIs, Scala easier to use via immutables
• Message passing pattern without all the JMS overhead
• 50 million msg/sec on a single machine + small memory footprint; ~2.5
million actors (message endpoints) per GB of heap
• Remoting can scale to tens of thousands of machines
Concurrency & Distribution
Part 2
• Use Akka – http://akka.io
• Scala and Java APIs, Scala easier to use via immutables
• Message passing pattern without all the JMS overhead
• 50 million msg/sec on a single machine + small memory footprint; ~2.5
million actors (message endpoints) per GB of heap
• Remoting can scale to tens of thousands of machines
• Akka Streams focuses on streaming messages, uses standard TCP
facilities to throttle clients, avoid buffer overflows
Concurrency & Distribution
Part 2
• Use Akka – http://akka.io
• Scala and Java APIs, Scala easier to use via immutables
• Message passing pattern without all the JMS overhead
• 50 million msg/sec on a single machine + small memory footprint; ~2.5
million actors (message endpoints) per GB of heap
• Remoting can scale to tens of thousands of machines
• Akka Streams focuses on streaming messages, uses standard TCP
facilities to throttle clients, avoid buffer overflows
• 2014Q1 test reached 2400 nodes as well as starting up a 1000 node
cluster in just over four minutes on Google App Engine.
Who's using it?
Who's using it?
Just about every major player
has something in Scala:
• Apple
• Intel
• Twitter
• Agoda
• Airbnb
Who's using it?
Just about every major player
has something in Scala:
• Apple
• Intel
• Twitter
• Agoda
• Airbnb
And any company using
these scaling technologies:
• Apache Spark
• Apache Scalding
• Apache Kafka
• Twitter Finagle
• Typesafe Akka
Lessons?
• Every developer has the power to enlighten or obfuscate
• Every developer has the power to enlighten or obfuscate
• Complexity has many different measures at many
different levels. The solution of least overall complexity
often hides behind greater surface complexity!
• Every developer has the power to enlighten or obfuscate
• Complexity has many different measures at many
different levels. The solution of least overall complexity
often hides behind greater surface complexity!
• Every developer has the power to enlighten or obfuscate
• Complexity has many different measures at many
different levels. The solution of least overall complexity
often hides behind greater surface complexity!
• On first glance, Functional Programming looks difficult,
but hundreds of years of proven advanced math are
what built society – bridges, buildings, cars, computers
• Every developer has the power to enlighten or obfuscate
• Complexity has many different measures at many
different levels. The solution of least overall complexity
often hides behind greater surface complexity!
• On first glance, Functional Programming looks difficult,
but hundreds of years of proven advanced math are
what built society – bridges, buildings, cars, computers
• Why reinvent that wheel? Allow mathematical induction
to help your efforts.
• Every developer has the power to enlighten or obfuscate
• Complexity has many different measures at many
different levels. The solution of least overall complexity
often hides behind greater surface complexity!
• On first glance, Functional Programming looks difficult,
but hundreds of years of proven advanced math are
what built society – bridges, buildings, cars, computers
• Why reinvent that wheel? Allow mathematical induction
to help your efforts.
• Moore's Law has given us blessings, including the ability
to use increasingly complex compilers.
References + Q&A
• Scala Course: 

https://www.coursera.org/course/progfun
• Please read chapter 1, available for free:

http://manning.com/kuhn/
• Twitter's Scala School:

http://twitter.github.io/scala_school/
• Scala Cheat Sheet : 

http://mbonaci.github.io/scala/
• Deeper insight:

http://danielwestheide.com/scala/neophytes.html

More Related Content

What's hot

Anaphora Resolution
Anaphora ResolutionAnaphora Resolution
Anaphora Resolution
Findwise
 
Stop Building It From Scratch: Creating Reusable eLearning Components
Stop Building It From Scratch: Creating Reusable eLearning ComponentsStop Building It From Scratch: Creating Reusable eLearning Components
Stop Building It From Scratch: Creating Reusable eLearning Components
Chad Udell
 
Writing DSL's in Scala
Writing DSL's in ScalaWriting DSL's in Scala
Writing DSL's in Scala
Abhijit Sharma
 
EclipseCon Europe 2011
EclipseCon Europe 2011EclipseCon Europe 2011
EclipseCon Europe 2011
Sigasi
 
Programming Languages #devcon2013
Programming Languages #devcon2013Programming Languages #devcon2013
Programming Languages #devcon2013
Iván Montes
 

What's hot (17)

Anaphora Resolution
Anaphora ResolutionAnaphora Resolution
Anaphora Resolution
 
Enlightenment: A Cross Platform Window Manager & Toolkit
Enlightenment: A Cross Platform Window Manager & ToolkitEnlightenment: A Cross Platform Window Manager & Toolkit
Enlightenment: A Cross Platform Window Manager & Toolkit
 
Stop Building It From Scratch: Creating Reusable eLearning Components
Stop Building It From Scratch: Creating Reusable eLearning ComponentsStop Building It From Scratch: Creating Reusable eLearning Components
Stop Building It From Scratch: Creating Reusable eLearning Components
 
44 Slides About 22 Modules
44 Slides About 22 Modules44 Slides About 22 Modules
44 Slides About 22 Modules
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03) iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03)
 
Writing DSL's in Scala
Writing DSL's in ScalaWriting DSL's in Scala
Writing DSL's in Scala
 
Using Scala for building DSLs
Using Scala for building DSLsUsing Scala for building DSLs
Using Scala for building DSLs
 
Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
 
Scala
ScalaScala
Scala
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Why Scala for Web 2.0?
Why Scala for Web 2.0?Why Scala for Web 2.0?
Why Scala for Web 2.0?
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
 
Jax keynote
Jax keynoteJax keynote
Jax keynote
 
NLP using JavaScript Natural Library
NLP using JavaScript Natural LibraryNLP using JavaScript Natural Library
NLP using JavaScript Natural Library
 
EclipseCon Europe 2011
EclipseCon Europe 2011EclipseCon Europe 2011
EclipseCon Europe 2011
 
Pragmatic Smalltalk
Pragmatic SmalltalkPragmatic Smalltalk
Pragmatic Smalltalk
 
Programming Languages #devcon2013
Programming Languages #devcon2013Programming Languages #devcon2013
Programming Languages #devcon2013
 

Viewers also liked

Functional Programming in Scala Reading #2
Functional Programming in Scala Reading #2Functional Programming in Scala Reading #2
Functional Programming in Scala Reading #2
Naoyuki Yamada
 
Functional Scala II (in practice)
Functional Scala II (in practice)Functional Scala II (in practice)
Functional Scala II (in practice)
Mario Gleichmann
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
Loïc Descotte
 

Viewers also liked (20)

Clean Code - How to write comprehensible code regarding cognitive abilities o...
Clean Code - How to write comprehensible code regarding cognitive abilities o...Clean Code - How to write comprehensible code regarding cognitive abilities o...
Clean Code - How to write comprehensible code regarding cognitive abilities o...
 
Functional Programming in Scala Reading #2
Functional Programming in Scala Reading #2Functional Programming in Scala Reading #2
Functional Programming in Scala Reading #2
 
Empathic Programming - How to write comprehensible code
Empathic Programming - How to write comprehensible codeEmpathic Programming - How to write comprehensible code
Empathic Programming - How to write comprehensible code
 
Scala: Object-Oriented Meets Functional, by Iulian Dragos
Scala: Object-Oriented Meets Functional, by Iulian DragosScala: Object-Oriented Meets Functional, by Iulian Dragos
Scala: Object-Oriented Meets Functional, by Iulian Dragos
 
Functional Scala II (in practice)
Functional Scala II (in practice)Functional Scala II (in practice)
Functional Scala II (in practice)
 
Functional Scala I
Functional Scala IFunctional Scala I
Functional Scala I
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: Notes
 
Software engineering 101 - The basics you should hear about at least once
Software engineering 101 - The basics you should hear about at least onceSoftware engineering 101 - The basics you should hear about at least once
Software engineering 101 - The basics you should hear about at least once
 
The hitchhicker’s guide to unit testing
The hitchhicker’s guide to unit testingThe hitchhicker’s guide to unit testing
The hitchhicker’s guide to unit testing
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Programming Actor-based Collective Adaptive Systems
Programming Actor-based Collective Adaptive SystemsProgramming Actor-based Collective Adaptive Systems
Programming Actor-based Collective Adaptive Systems
 
Basic Wicket and Scala
Basic Wicket and ScalaBasic Wicket and Scala
Basic Wicket and Scala
 
Scala 2.10.0 (english version)
Scala 2.10.0 (english version)Scala 2.10.0 (english version)
Scala 2.10.0 (english version)
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
Functional Programming in Scala: Notes
Functional Programming in Scala: NotesFunctional Programming in Scala: Notes
Functional Programming in Scala: Notes
 
Scala vs Ruby
Scala vs RubyScala vs Ruby
Scala vs Ruby
 
Scala - A Scalable Language
Scala - A Scalable LanguageScala - A Scalable Language
Scala - A Scalable Language
 
Scala For Java Programmers
Scala For Java ProgrammersScala For Java Programmers
Scala For Java Programmers
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
 

Similar to Software Engineering Thailand: Programming with Scala

Similar to Software Engineering Thailand: Programming with Scala (20)

Java Closures
Java ClosuresJava Closures
Java Closures
 
Complete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itComplete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept it
 
Polyglot Grails
Polyglot GrailsPolyglot Grails
Polyglot Grails
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprises
 
Scala-Ls1
Scala-Ls1Scala-Ls1
Scala-Ls1
 
3 years with Clojure
3 years with Clojure3 years with Clojure
3 years with Clojure
 
Cucumber in Practice(en)
Cucumber in Practice(en)Cucumber in Practice(en)
Cucumber in Practice(en)
 
Introduction to Scala JS
Introduction to Scala JSIntroduction to Scala JS
Introduction to Scala JS
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
 
C# .NET - Um overview da linguagem
C# .NET - Um overview da linguagem C# .NET - Um overview da linguagem
C# .NET - Um overview da linguagem
 
Challenges of moving a java team to scala
Challenges of moving a java team to scalaChallenges of moving a java team to scala
Challenges of moving a java team to scala
 
Into the Land of lambda, One Programmer's Journey Into Functional Programming
Into the Land of lambda, One Programmer's Journey Into Functional ProgrammingInto the Land of lambda, One Programmer's Journey Into Functional Programming
Into the Land of lambda, One Programmer's Journey Into Functional Programming
 
Deployment is the new build
Deployment is the new buildDeployment is the new build
Deployment is the new build
 
Kubernetes and AWS Lambda can play nicely together
Kubernetes and AWS Lambda can play nicely togetherKubernetes and AWS Lambda can play nicely together
Kubernetes and AWS Lambda can play nicely together
 
Android java fx-jme@jug-lugano
Android java fx-jme@jug-luganoAndroid java fx-jme@jug-lugano
Android java fx-jme@jug-lugano
 
Functional OOP, Clojure style
Functional OOP, Clojure styleFunctional OOP, Clojure style
Functional OOP, Clojure style
 
QA / Testing Tools, Automation Testing, Online & Classroom Training
QA / Testing Tools, Automation Testing, Online & Classroom Training QA / Testing Tools, Automation Testing, Online & Classroom Training
QA / Testing Tools, Automation Testing, Online & Classroom Training
 
Scala Bay Meetup - The state of Scala code style and quality
Scala Bay Meetup - The state of Scala code style and qualityScala Bay Meetup - The state of Scala code style and quality
Scala Bay Meetup - The state of Scala code style and quality
 
Rootcon X - Reverse Engineering Swift Applications
Rootcon X - Reverse Engineering Swift ApplicationsRootcon X - Reverse Engineering Swift Applications
Rootcon X - Reverse Engineering Swift Applications
 

Recently uploaded

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 

Software Engineering Thailand: Programming with Scala

  • 1. Programming with Scala Brian Topping Mauswerks LLC
  • 2. About Me • Globally experienced dev with over 25 years professional experience • Have led teams of three to fifteen developers as lead developer, architect, general manager. Start projects first, then hire when ten fingers are not enough. • Have been using Scala since 2012, JDK Open Source since 2001 • Interests: Functional Reactive Programming, financial markets, machine learning, Javascript, travel, motorcycles • Shameless plug: Available for investment or work in BKK • http://github.com/briantopping
 http://twitter.com/briantopping
 http://linkedin.com/in/briantopping
  • 4. What is wrong with this picture?
  • 5. • "Looks good to me, ship it!"
  • 6. • "Looks good to me, ship it!" • We're at the wrong level of zoom to see problems

  • 7. • "Looks good to me, ship it!" • We're at the wrong level of zoom to see problems
 • 

  • 8. • "Looks good to me, ship it!" • We're at the wrong level of zoom to see problems
 • 
 • Solutions at a global level must factor problems at the local level.
  • 9. • "Looks good to me, ship it!" • We're at the wrong level of zoom to see problems
 • 
 • Solutions at a global level must factor problems at the local level. • Complexity is the natural tradeoff
  • 10. What is Scala? • Object Oriented / Functional hybrid • Compiled to JVM bytecode • Statically typed (compile time) • Strongly typed (types must match) • Growing ecosystem • Language is stable and mature
  • 11. (a few) Benefits of Scala • Seamless Java / JDK ecosystem interoperability • Type Inferencing & Parameterization • Concurrency & Distribution • Collections Classes • Pattern Matching • Obvious Correctness
  • 13. Standard Example • Java "Bean"
 
 
 
 
 
 
 

  • 14. Standard Example • Java "Bean"
 
 
 
 
 
 
 

  • 15. Standard Example • Java "Bean"
 
 
 
 
 
 
 
 • Scala Case Class
  • 16. Standard Example • Java "Bean"
 
 
 
 
 
 
 
 • Scala Case Class
  • 17. Standard Example • Java "Bean"
 
 
 
 
 
 
 
 • Scala Case Class
  • 18. Java / JDK Interoperability
  • 19. Java / JDK Interoperability • Scala classes are JVM classes
  • 20. Java / JDK Interoperability • Scala classes are JVM classes • Groovy, Clojure, JRuby, Jython – 40+ in all!
  • 21. Java / JDK Interoperability • Scala classes are JVM classes • Groovy, Clojure, JRuby, Jython – 40+ in all! • Scala is a mixed Object + Functional language
  • 22. Java / JDK Interoperability • Scala classes are JVM classes • Groovy, Clojure, JRuby, Jython – 40+ in all! • Scala is a mixed Object + Functional language • It is possible and common for young teams to start writing Scala with Java style (OOD) and API, test with existing tools
  • 23. Java / JDK Interoperability • Scala classes are JVM classes • Groovy, Clojure, JRuby, Jython – 40+ in all! • Scala is a mixed Object + Functional language • It is possible and common for young teams to start writing Scala with Java style (OOD) and API, test with existing tools • Take advantage of Java libraries
  • 24. Java / JDK Interoperability • Scala classes are JVM classes • Groovy, Clojure, JRuby, Jython – 40+ in all! • Scala is a mixed Object + Functional language • It is possible and common for young teams to start writing Scala with Java style (OOD) and API, test with existing tools • Take advantage of Java libraries
  • 26. Type Inference & Immutability Focus • Compiler knows the type of an assignment, yet most languages require the developer to prove it
  • 27. Type Inference & Immutability Focus • Compiler knows the type of an assignment, yet most languages require the developer to prove it • Java:
  • 28. Type Inference & Immutability Focus • Compiler knows the type of an assignment, yet most languages require the developer to prove it • Java: • Scala:
  • 29. Type Inference & Immutability Focus • Compiler knows the type of an assignment, yet most languages require the developer to prove it • Java: • Scala: • Built for immutability!
  • 30. Type Inference & Immutability Focus • Compiler knows the type of an assignment, yet most languages require the developer to prove it • Java: • Scala: • Built for immutability! • Use the var keyword for mutable variables
  • 31. Type Inference & Immutability Focus • Compiler knows the type of an assignment, yet most languages require the developer to prove it • Java: • Scala: • Built for immutability! • Use the var keyword for mutable variables • One finds themselves using it less and less often!
  • 33. Type Parameterization • Types allow you to denote function domain & codomains. For example, from mathematics, we are used to seeing:
 
 
 this tells us that function “f” maps values from the set of real numbers to values of the set of natural numbers
  • 34. Type Parameterization • Types allow you to denote function domain & codomains. For example, from mathematics, we are used to seeing:
 
 
 this tells us that function “f” maps values from the set of real numbers to values of the set of natural numbers • In the abstract, this is exactly what concrete types are. Type systems give us some more powerful ways to express these sets
  • 35. Type Parameterization • Types allow you to denote function domain & codomains. For example, from mathematics, we are used to seeing:
 
 
 this tells us that function “f” maps values from the set of real numbers to values of the set of natural numbers • In the abstract, this is exactly what concrete types are. Type systems give us some more powerful ways to express these sets • Given these annotations, the compiler can now statically (at compile time) verify that the program is sound
  • 36. Type Parameterization • Types allow you to denote function domain & codomains. For example, from mathematics, we are used to seeing:
 
 
 this tells us that function “f” maps values from the set of real numbers to values of the set of natural numbers • In the abstract, this is exactly what concrete types are. Type systems give us some more powerful ways to express these sets • Given these annotations, the compiler can now statically (at compile time) verify that the program is sound • Variance annotations allow you to express relationships between class hierarchies & polymorphic types
  • 37. Type Parameterization • Types allow you to denote function domain & codomains. For example, from mathematics, we are used to seeing:
 
 
 this tells us that function “f” maps values from the set of real numbers to values of the set of natural numbers • In the abstract, this is exactly what concrete types are. Type systems give us some more powerful ways to express these sets • Given these annotations, the compiler can now statically (at compile time) verify that the program is sound • Variance annotations allow you to express relationships between class hierarchies & polymorphic types • Reference: http://twitter.github.io/scala_school/type-basics.html
  • 39. Concurrency & Distribution • Futures and Promises – Long history across platforms
  • 40. Concurrency & Distribution • Futures and Promises – Long history across platforms • Factory objects look like integral part of language
  • 41. Concurrency & Distribution • Futures and Promises – Long history across platforms • Factory objects look like integral part of language • Remember that functions are parameters!
  • 42. Concurrency & Distribution • Futures and Promises – Long history across platforms • Factory objects look like integral part of language • Remember that functions are parameters! • 

  • 43. Concurrency & Distribution • Futures and Promises – Long history across platforms • Factory objects look like integral part of language • Remember that functions are parameters! • 
 • Don't return values, return a Future!
  • 44. Concurrency & Distribution • Futures and Promises – Long history across platforms • Factory objects look like integral part of language • Remember that functions are parameters! • 
 • Don't return values, return a Future! • Akka-HTTP is a perfect example, you can return a value, but then your code manages the concurrency. Return a Future to the caller and let it manage it instead!
  • 45. Concurrency & Distribution • Futures and Promises – Long history across platforms • Factory objects look like integral part of language • Remember that functions are parameters! • 
 • Don't return values, return a Future! • Akka-HTTP is a perfect example, you can return a value, but then your code manages the concurrency. Return a Future to the caller and let it manage it instead! • Unlike Node, full access to all cores.
  • 47. Collections Classes • Scala Collections are what brought me to the language
  • 48. Collections Classes • Scala Collections are what brought me to the language • Designed to consistently behave as a collections DSL
  • 49. Collections Classes • Scala Collections are what brought me to the language • Designed to consistently behave as a collections DSL • Immutable by default, great for parallel deployments
  • 50. Collections Classes • Scala Collections are what brought me to the language • Designed to consistently behave as a collections DSL • Immutable by default, great for parallel deployments • Java
  • 51. Collections Classes • Scala Collections are what brought me to the language • Designed to consistently behave as a collections DSL • Immutable by default, great for parallel deployments • Java •
  • 52. Collections Classes • Scala Collections are what brought me to the language • Designed to consistently behave as a collections DSL • Immutable by default, great for parallel deployments • Java • • Scala
  • 53. Collections Classes • Scala Collections are what brought me to the language • Designed to consistently behave as a collections DSL • Immutable by default, great for parallel deployments • Java • • Scala •
  • 54. Collections Classes • Scala Collections are what brought me to the language • Designed to consistently behave as a collections DSL • Immutable by default, great for parallel deployments • Java • • Scala • • Don't get the wrong idea here! Rolling a one-liner into a println is not what I'd call "good style". Instead, note how the functional transparency and type inferencing allows us to inline functions as easily as we can assign them to variables.
  • 56. Pattern Matching • Partial Functions – A function that is only defined for specific input values 

  • 57. Pattern Matching • Partial Functions – A function that is only defined for specific input values 
 • 

  • 58. Pattern Matching • Partial Functions – A function that is only defined for specific input values 
 • 
 • Regular Expressions – Please enjoy them now! 😉
  • 59. Pattern Matching • Partial Functions – A function that is only defined for specific input values 
 • 
 • Regular Expressions – Please enjoy them now! 😉 •
  • 61. Obvious Correctness • Trick question: Which of these is more obviously correct?
 
 

  • 62. Obvious Correctness • Trick question: Which of these is more obviously correct?
 
 
 • Java:
 
 
 

  • 63. Obvious Correctness • Trick question: Which of these is more obviously correct?
 
 
 • Java:
 
 
 
 • Scala:
  • 64. Obvious Correctness • Trick question: Which of these is more obviously correct?
 
 
 • Java:
 
 
 
 • Scala: • Depends on experience!!
  • 66. Team Evolution w/ Scala • Start with this:
 
 
 

  • 67. Team Evolution w/ Scala • Start with this:
 
 
 
 • To get to this:

  • 68. Team Evolution w/ Scala • Start with this:
 
 
 
 • To get to this:
 • Make the transition gradually! Do it together as a team!
  • 69. What does all this buy us?
  • 70. What does all this buy us? • Pure functions have no side effects... data in, data out
  • 71. What does all this buy us? • Pure functions have no side effects... data in, data out • Objects maintain state. This is why Scala is not considered a purely functional language!
  • 72. What does all this buy us? • Pure functions have no side effects... data in, data out • Objects maintain state. This is why Scala is not considered a purely functional language! • When objects are immutable though, the state acts as constants in the functions. Constants are thread-safe!
  • 73. What does all this buy us? • Pure functions have no side effects... data in, data out • Objects maintain state. This is why Scala is not considered a purely functional language! • When objects are immutable though, the state acts as constants in the functions. Constants are thread-safe! • Immutable objects do not need to be locked. Locking is actually very expensive and error prone
  • 74. What does all this buy us? • Pure functions have no side effects... data in, data out • Objects maintain state. This is why Scala is not considered a purely functional language! • When objects are immutable though, the state acts as constants in the functions. Constants are thread-safe! • Immutable objects do not need to be locked. Locking is actually very expensive and error prone • Immutable state is updated by replacing the object!
  • 75. But it looks so complex!
  • 76. But it looks so complex! • Scala actually has a smaller grammar than Java
  • 77. But it looks so complex! • Scala actually has a smaller grammar than Java • Functional composition (the ability for one function to feed another) allows intermediate variables to be removed.
  • 78. But it looks so complex! • Scala actually has a smaller grammar than Java • Functional composition (the ability for one function to feed another) allows intermediate variables to be removed. • Scala ends up looking complex because developers collapse code that maybe shouldn't be collapsed.
  • 79. But it looks so complex! • Scala actually has a smaller grammar than Java • Functional composition (the ability for one function to feed another) allows intermediate variables to be removed. • Scala ends up looking complex because developers collapse code that maybe shouldn't be collapsed. • Program so your code is readable, not so it fits in as few lines as possible.
  • 80. But it looks so complex! • Scala actually has a smaller grammar than Java • Functional composition (the ability for one function to feed another) allows intermediate variables to be removed. • Scala ends up looking complex because developers collapse code that maybe shouldn't be collapsed. • Program so your code is readable, not so it fits in as few lines as possible. • Occam's Razor: We should reduce to the simplest possible outcome, and no simpler!
  • 82. Some things haven't changed • TDD – Use it! Create unit tests for everything, use them as documentation
  • 83. Some things haven't changed • TDD – Use it! Create unit tests for everything, use them as documentation • One liners should have a simple comment describing what they do 

  • 84. Some things haven't changed • TDD – Use it! Create unit tests for everything, use them as documentation • One liners should have a simple comment describing what they do 
 • Frequent code reviews! Pull requests that receive no comments are to be avoided.
  • 85. Some things haven't changed • TDD – Use it! Create unit tests for everything, use them as documentation • One liners should have a simple comment describing what they do 
 • Frequent code reviews! Pull requests that receive no comments are to be avoided. • Avoid learning a new technique and immediately using it everywhere.
  • 86. Some things haven't changed • TDD – Use it! Create unit tests for everything, use them as documentation • One liners should have a simple comment describing what they do 
 • Frequent code reviews! Pull requests that receive no comments are to be avoided. • Avoid learning a new technique and immediately using it everywhere. • If you are the only person that can maintain your code, you will be cursed to own it forever.
  • 87. Some things haven't changed • TDD – Use it! Create unit tests for everything, use them as documentation • One liners should have a simple comment describing what they do 
 • Frequent code reviews! Pull requests that receive no comments are to be avoided. • Avoid learning a new technique and immediately using it everywhere. • If you are the only person that can maintain your code, you will be cursed to own it forever. • If you can inspire others to read your code because it is both short and people "learn one new thing" (only one!), you will be able to move the team forward with new techniques, do more with less, have fun!
  • 88. I'm not sold yet...
  • 89. I'm not sold yet... • Take Coursera's Scala class taught by Martin Odersky
  • 90. I'm not sold yet... • Take Coursera's Scala class taught by Martin Odersky • You will become a better Scala programmer
  • 91. I'm not sold yet... • Take Coursera's Scala class taught by Martin Odersky • You will become a better Scala programmer • You will become a better Java programmer
  • 92. I'm not sold yet... • Take Coursera's Scala class taught by Martin Odersky • You will become a better Scala programmer • You will become a better Java programmer • You will become a better programmer
  • 93. I'm not sold yet... • Take Coursera's Scala class taught by Martin Odersky • You will become a better Scala programmer • You will become a better Java programmer • You will become a better programmer • Apple's Swift language is a bit of a knockoff
  • 94. I'm not sold yet... • Take Coursera's Scala class taught by Martin Odersky • You will become a better Scala programmer • You will become a better Java programmer • You will become a better programmer • Apple's Swift language is a bit of a knockoff • Get two platforms for the price of one!
  • 95. How Do I Get Started?
  • 99. IDEs: IntelliJ vs. Eclipse • They both have advantages. Each team should "bake off" and doc the results
  • 100. IDEs: IntelliJ vs. Eclipse • They both have advantages. Each team should "bake off" and doc the results • Don't be restricted to one, but a common denominator of skills is helpful         
  • 103. Testing • ScalaTest is standard • Behavior Driven Development
  • 104. Testing • ScalaTest is standard • Behavior Driven Development • Use with TDD, just works!
  • 105. Testing • ScalaTest is standard • Behavior Driven Development • Use with TDD, just works! • The power is in the Matchers
 
 
 
 
 

  • 107. Development Environments • REPL (Read-Eval-Print Loop) is an interactive shell
  • 108. Development Environments • REPL (Read-Eval-Print Loop) is an interactive shell • scalac compiler can be run from command line like javac
  • 109. Development Environments • REPL (Read-Eval-Print Loop) is an interactive shell • scalac compiler can be run from command line like javac • SBT is Scala's own build tool, allows Scala code to be used within build, but not very IDE friendly.
  • 110. Development Environments • REPL (Read-Eval-Print Loop) is an interactive shell • scalac compiler can be run from command line like javac • SBT is Scala's own build tool, allows Scala code to be used within build, but not very IDE friendly. • Maven has a Scala plugin, but comes with all of Maven's idiosyncrasies.
  • 111. Development Environments • REPL (Read-Eval-Print Loop) is an interactive shell • scalac compiler can be run from command line like javac • SBT is Scala's own build tool, allows Scala code to be used within build, but not very IDE friendly. • Maven has a Scala plugin, but comes with all of Maven's idiosyncrasies. • SBT can use Maven central repository, but is designed for Ivy repositories. Both end up being required, which is a pain point.
  • 112. Development Environments • REPL (Read-Eval-Print Loop) is an interactive shell • scalac compiler can be run from command line like javac • SBT is Scala's own build tool, allows Scala code to be used within build, but not very IDE friendly. • Maven has a Scala plugin, but comes with all of Maven's idiosyncrasies. • SBT can use Maven central repository, but is designed for Ivy repositories. Both end up being required, which is a pain point. • All the cool kids use SBT, but it's not as mature and harder to use with projects that span multiple source repositories, also not as simple for tagged release environments.
  • 113. Development Environments • REPL (Read-Eval-Print Loop) is an interactive shell • scalac compiler can be run from command line like javac • SBT is Scala's own build tool, allows Scala code to be used within build, but not very IDE friendly. • Maven has a Scala plugin, but comes with all of Maven's idiosyncrasies. • SBT can use Maven central repository, but is designed for Ivy repositories. Both end up being required, which is a pain point. • All the cool kids use SBT, but it's not as mature and harder to use with projects that span multiple source repositories, also not as simple for tagged release environments. • Verdict: If you already use Maven, stick with it, otherwise use SBT.
  • 115. Concurrency & Distribution Part 2 • Use Akka – http://akka.io
  • 116. Concurrency & Distribution Part 2 • Use Akka – http://akka.io • Scala and Java APIs, Scala easier to use via immutables
  • 117. Concurrency & Distribution Part 2 • Use Akka – http://akka.io • Scala and Java APIs, Scala easier to use via immutables • Message passing pattern without all the JMS overhead
  • 118. Concurrency & Distribution Part 2 • Use Akka – http://akka.io • Scala and Java APIs, Scala easier to use via immutables • Message passing pattern without all the JMS overhead • 50 million msg/sec on a single machine + small memory footprint; ~2.5 million actors (message endpoints) per GB of heap
  • 119. Concurrency & Distribution Part 2 • Use Akka – http://akka.io • Scala and Java APIs, Scala easier to use via immutables • Message passing pattern without all the JMS overhead • 50 million msg/sec on a single machine + small memory footprint; ~2.5 million actors (message endpoints) per GB of heap • Remoting can scale to tens of thousands of machines
  • 120. Concurrency & Distribution Part 2 • Use Akka – http://akka.io • Scala and Java APIs, Scala easier to use via immutables • Message passing pattern without all the JMS overhead • 50 million msg/sec on a single machine + small memory footprint; ~2.5 million actors (message endpoints) per GB of heap • Remoting can scale to tens of thousands of machines • Akka Streams focuses on streaming messages, uses standard TCP facilities to throttle clients, avoid buffer overflows
  • 121. Concurrency & Distribution Part 2 • Use Akka – http://akka.io • Scala and Java APIs, Scala easier to use via immutables • Message passing pattern without all the JMS overhead • 50 million msg/sec on a single machine + small memory footprint; ~2.5 million actors (message endpoints) per GB of heap • Remoting can scale to tens of thousands of machines • Akka Streams focuses on streaming messages, uses standard TCP facilities to throttle clients, avoid buffer overflows • 2014Q1 test reached 2400 nodes as well as starting up a 1000 node cluster in just over four minutes on Google App Engine.
  • 123. Who's using it? Just about every major player has something in Scala: • Apple • Intel • Twitter • Agoda • Airbnb
  • 124. Who's using it? Just about every major player has something in Scala: • Apple • Intel • Twitter • Agoda • Airbnb And any company using these scaling technologies: • Apache Spark • Apache Scalding • Apache Kafka • Twitter Finagle • Typesafe Akka
  • 126. • Every developer has the power to enlighten or obfuscate
  • 127. • Every developer has the power to enlighten or obfuscate • Complexity has many different measures at many different levels. The solution of least overall complexity often hides behind greater surface complexity!
  • 128. • Every developer has the power to enlighten or obfuscate • Complexity has many different measures at many different levels. The solution of least overall complexity often hides behind greater surface complexity!
  • 129. • Every developer has the power to enlighten or obfuscate • Complexity has many different measures at many different levels. The solution of least overall complexity often hides behind greater surface complexity! • On first glance, Functional Programming looks difficult, but hundreds of years of proven advanced math are what built society – bridges, buildings, cars, computers
  • 130. • Every developer has the power to enlighten or obfuscate • Complexity has many different measures at many different levels. The solution of least overall complexity often hides behind greater surface complexity! • On first glance, Functional Programming looks difficult, but hundreds of years of proven advanced math are what built society – bridges, buildings, cars, computers • Why reinvent that wheel? Allow mathematical induction to help your efforts.
  • 131. • Every developer has the power to enlighten or obfuscate • Complexity has many different measures at many different levels. The solution of least overall complexity often hides behind greater surface complexity! • On first glance, Functional Programming looks difficult, but hundreds of years of proven advanced math are what built society – bridges, buildings, cars, computers • Why reinvent that wheel? Allow mathematical induction to help your efforts. • Moore's Law has given us blessings, including the ability to use increasingly complex compilers.
  • 132. References + Q&A • Scala Course: 
 https://www.coursera.org/course/progfun • Please read chapter 1, available for free:
 http://manning.com/kuhn/ • Twitter's Scala School:
 http://twitter.github.io/scala_school/ • Scala Cheat Sheet : 
 http://mbonaci.github.io/scala/ • Deeper insight:
 http://danielwestheide.com/scala/neophytes.html

Editor's Notes

  1. Scala is a functional language backed by objects JVM bytecode is no different than what is used by compiled Java Static typing contributes to performance Language has been stable (arguably) since 2.10
  2. Going to go through these one by one throughout the presentation
  3. Let's start with a typical Java Bean or POJO Now let's take a look at a Scala case class
  4. 40+ languages compile to JVM bytecode, even interpreted ones. Last build on Java libraries: That said, Scala libraries are generally duplicating Java libraries for DSL oriented APIs.
  5. This is all about reducing work on the part of the developer, but increasing safety across the project Better safety == happier team
  6. Type parameterization is actually very functional in nature as it applies to mathematics.
  7. A bit inaccurate, Akka HTTP brought me to the language. When I saw the kind of minds that were working on Scala, I wanted to know why. Scala collections showed me why.