The document provides an agenda for a presentation on multi-paradigm programming in Scala and Akka. The presentation will demonstrate how Scala allows a blend of object-oriented and functional programming, and how Scala can be used with Akka to build scalable actor systems. It will also discuss why considering another programming paradigm could be beneficial and how functional programming can improve code quality.
3. Agenda for tonight
⊸Demonstrate a blend of OOP and
FP in a hybrid language - Scala
⊸Use Scala with Akka to easily
build scalable Actor Systems
4. ⊸ Disclaimer:
▫ This is not a talk about Scala as a language, its features or its
comparison with Java.
Don’t want to do this =>
▫ As polyglot programmers, we acknowledge that some languages
are better than others for the specific kind of problems that they
are trying to solve.
▫ Scala and Java are just being used as tools to understand and
help in embracing functional programming paradigm.
5. ➢ Why should you consider another programming
paradigm?
8. ➢ What is the Best code?
○ The best code is the one that doesn't exists.
Why?
○ Code rots.
○ needs maintenance.
○ needs to be tested.
○ needs to be read and understood again and again
over time.
Conciseness matters!
13. ➢ Why Scala?
○ Because Scala smoothens the transition from
OOP to FP.
○ Supplements Java and adds more features and
reduces the verbosity.
○ It is not new - first introduced in 2003.
15. ➢ Why learn Functional Programming ?
○ Write high-performing code that's easier to
understand and reason about.
○ Write programs that can utilize multiple cores
more efficiently.
○ It would evolve your way of thinking about
programs and eventually make you a better
programmer.
17. ➢ How does FP improve code?
○ Scalable and efficient code that can utilize
multiple cores better - Map/Reduce engines.
○ Better to reason about code. No need to create
mental model or remember gradual state
changes.
○ By emphasizing on the evaluation of expressions
instead of evaluation of statements
18. ➢ What is functional programming ?
○ Immutability.
○ Referential transparency.
○ Higher order functions.
○ Tail call recursion, mapping, reducing, currying,
lazy evaluation,...
19. ➢ What is functional programming ?
○ Immutability.
○ Referential transparency.
○ Higher order functions.
○ Tail call recursion, mapping, reducing, currying,
lazy evaluation,...
➢ Writing code without side effects.
It is a restriction on how we write programs and not
on what programs we can express.
22. ➢ Immutability (preferred)
○ Preventing reference reassignment through val.
○ Avoiding mutable state through immutable
collections.
■ Eg : 2 threads referring to same tree.
23. ➢ After one thread adds a node.
○ Immutability has benefits in concurrency as
synchronization is not needed.
24. ➢ Having referential transparency.
○ Should hold substitution model.
➢ No side effects
25. ➢ Having referential transparency.
○ Should hold substitution model.
➢ No side effects
StringBuilder.append has side effects!
29. ➢ Function with Side Effect
○ A function has side effects if it does something
other than simply return a result like
■ Modifying a variable/data structure.
■ Throwing exception or halting abruptly.
■ Reading/writing to file/database
■ …
➢ In a pure function
○ Input is obtained only by parameters.
○ Output is calculated and returned.
31. ➢ Case classes
○ Regular classes which export their constructor
parameters and which provide a recursive
decomposition mechanism via pattern
matching.
○ The params can be accessed with .(dot)
notation.
33. ➢ Pattern matching
○ A pattern match includes a sequence of
alternatives, each starting with the keyword
‘case’.
○ Each alternative case includes a pattern and
one or more expressions, which will be
evaluated if the pattern matches.
○ An arrow symbol => separates the pattern from
the expressions.
Example =>
38. The Actor Model
⊸Avoiding shared mutable state
▫ Functional Programming - all state is immutable
▫ Actor Model - state is mutable but encapsulated in
actors
39. What’s an actor?
⊸An actor has state
⊸An actor has behaviour
⊸….
Sounds similar to something else, doesn’t it?
40. Actors are what “objects” were supposed to be
⊸Actors are what objects are
supposed to be (Smalltalk
objects)
41. What’s an actor?
⊸An actor has state
⊸An actor has behaviour
Similar to OOP objects but with one difference
⊸Actors communicate by sending immutable messages
to each other
42. Akka - actors on the JVM
⊸Akka actors
▫ are light-weight JVM objects
▫ are guaranteed to run on a single thread (no
locks/synchronization required)
▫ process messages sent to them in order and one at
a time
▫ do not share their state
43. What is Akka?
Akka is a toolkit and runtime for building highly
concurrent, distributed, and resilient message-driven
applications on the JVM.
44. Anatomy of an actor
An akka actor must have
⊸State
⊸Behavior
▫ Message processing
51. Instructions for use
Open this document in Google Slides (if you are at slidescarnival.com use the button below this
presentation)
You have to be signed in to your Google account
EDIT IN GOOGLE SLIDES
Go to the File menu and select Make a copy.
You will get a copy of this document on your
Google Drive and will be able to edit, add or
delete slides.
EDIT IN POWERPOINT®
Go to the File menu and select Download as
Microsoft PowerPoint. You will get a .pptx file
that you can edit in PowerPoint.
Remember to download and install the fonts
used in this presentation (you’ll find the links
to the font files needed in the Presentation
design slide)
More info on how to use this template at www.slidescarnival.com/help-use-presentation-
template
This template is free to use under Creative Commons Attribution license. You can keep the Credits
slide or mention SlidesCarnival and other resources used in a slide footer.
52. hello!
I am Jayden Smith
I am here because I love to give presentations.
You can find me at @username
54. “
Quotations are commonly printed as a means of
inspiration and to invoke philosophical thoughts
from the reader.
55. This is a slide title
▣ Here you have a list of items
▣ And some text
▣ But remember not to overload your slides with
content
You audience will listen to you or read the content, but
won’t do both.
56. big concept
Bring the attention of your audience over a key
concept using icons or illustrations
57. White
Is the color of milk and fresh
snow, the color produced by the
combination of all the colors of
the visible spectrum.
You can also split your content
Black
Is the color of coal, ebony, and
of outer space. It is the darkest
color, the result of the absence
of or complete absorption of
light.
58. In two or three columns
Yellow
Is the color of gold,
butter and ripe lemons.
In the spectrum of
visible light, yellow is
found between green and
orange.
Blue
Is the colour of the clear
sky and the deep sea. It
is located between violet
and green on the optical
spectrum.
Red
Is the color of blood, and
because of this it has
historically been
associated with sacrifice,
danger and courage.
59. A picture is worth a thousand words
A complex idea can be conveyed with just a single still
image, namely making it possible to absorb large amounts of
data quickly.
67. Let’s review some concepts
Yellow
Is the color of gold, butter and
ripe lemons. In the spectrum of
visible light, yellow is found
between green and orange.
Blue
Is the colour of the clear sky and
the deep sea. It is located
between violet and green on the
optical spectrum.
Red
Is the color of blood, and
because of this it has historically
been associated with sacrifice,
danger and courage.
Yellow
Is the color of gold, butter and
ripe lemons. In the spectrum of
visible light, yellow is found
between green and orange.
Blue
Is the colour of the clear sky and
the deep sea. It is located
between violet and green on the
optical spectrum.
Red
Is the color of blood, and
because of this it has historically
been associated with sacrifice,
danger and courage.
74. Credits
Special thanks to all the people who made and
released these awesome resources for free:
▣ Presentation template by SlidesCarnival
▣ Photographs by Unsplash
75. Presentation design
This presentations uses the following typographies:
▣ Titles: Playfair Display
▣ Body copy: PT Serif
You can download the fonts on this page:
https://www.google.com/fonts#UsePlace:use/Collection:Playfair+Display|PT+Serif
Click on the “arrow button” that appears on the top right
You don’t need to keep this slide in your presentation. It’s only here to serve you as a design guide if you need to
create new slides or download the fonts to edit the presentation in PowerPoint®
76. SlidesCarnival icons are editable shapes.
This means that you can:
● Resize them without losing quality.
● Change line color, width and style.
Isn’t that nice? :)
Examples:
77. Now you can use any emoji as an icon!
And of course it resizes without losing quality and you can change the color.
How? Follow Google instructions
https://twitter.com/googledocs/status/730087240156643328
✋👆👉👍👤👦👧👨👩👪💃🏃💑❤😂
😉😋😒😭👶😸🐟🍒🍔💣📌📖🔨🎃🎈
🎨🏈🏰🌏🔌🔑 and many more...
😉
Editor's Notes
Actors are what objects should have been:
An actor is a process that executes a function.
… Actors never share state and thus never need to compete for locks for access to shared data.
Instead, actors share data by sending messages that are immutable.
Immutable data cannot be modified, so reads do not require a lock.
Messages are sent asynchronously and are buffered in an actor’s mailbox.
A mailbox is essentially a queue with multiple producers (other actors) and a single consumer.
A particular actor is driven by receiving messages from the mailbox based on pattern matching.