SlideShare a Scribd company logo
1 of 77
Multi-paradigm
programming in
Scala and Akka
Why not both?
You really don’t have to choose just
one.
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
⊸ 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.
➢ Why should you consider another programming
paradigm?
➢ What is the Best code?
➢ What is the Best code?
○ The following =>
➢ 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!
➢ Get all products from the orders
➢ Get all products from the orders
Or
➢ Sort the products by Id
Or
➢ 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.
➢ Why learn Functional Programming ?
➢ 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.
➢ How does FP improve code?
➢ 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
➢ What is functional programming ?
○ Immutability.
○ Referential transparency.
○ Higher order functions.
○ Tail call recursion, mapping, reducing, currying,
lazy evaluation,...
➢ 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.
➢ What makes Scala functional ?
➢ Functions are 1st class citizens =>
○ Instead =>
➢ Immutability (preferred)
○ Preventing reference reassignment through val.
○ Avoiding mutable state through immutable
collections.
■ Eg : 2 threads referring to same tree.
➢ After one thread adds a node.
○ Immutability has benefits in concurrency as
synchronization is not needed.
➢ Having referential transparency.
○ Should hold substitution model.
➢ No side effects
➢ Having referential transparency.
○ Should hold substitution model.
➢ No side effects
StringBuilder.append has side effects!
String is referentially transparent and holds
substitution model.
➢ Similarly,
add() here is also without side-effects and
referentially transparent.
➢ 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.
➢ Just enough Scala for Akka.
➢ 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.
➢ Pattern matching
○ Switch case on steroids
➢ 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 =>
➢ Pattern matching
The Actor Model
⊸Avoiding shared mutable state
▫ Functional Programming - all state is immutable
▫ Actor Model - state is mutable but encapsulated in
actors
What’s an actor?
⊸An actor has state
⊸An actor has behaviour
⊸….
Sounds similar to something else, doesn’t it?
Actors are what “objects” were supposed to be
⊸Actors are what objects are
supposed to be (Smalltalk
objects)
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
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
What is Akka?
Akka is a toolkit and runtime for building highly
concurrent, distributed, and resilient message-driven
applications on the JVM.
Anatomy of an actor
An akka actor must have
⊸State
⊸Behavior
▫ Message processing
State
Processing messages
Let’s look at an actor
DEMO
Scaling out in clusters
Seperator
The original template slides are below this slide
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.
hello!
I am Jayden Smith
I am here because I love to give presentations.
You can find me at @username
1.
Transition headline
Let’s start with the first set of slides
“
Quotations are commonly printed as a means of
inspiration and to invoke philosophical thoughts
from the reader.
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.
big concept
Bring the attention of your audience over a key
concept using icons or illustrations
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.
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.
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.
want big impact?
Use big image
Use charts to explain your ideas
White BlackGray
And tables to compare data
A B C
Yellow 10 20 7
Blue 30 15 10
Orange 5 24 16
Maps
our office
89,526,124
Whoa! That’s a big number, aren’t you proud?
89,526,124$
That’s a lot of money
100%
Total success!
185,244 users
And a lot of users
Our process is easy
first second last
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.
You can copy&paste graphs from Google Sheets
Android project
Show and explain your web, app
or software projects using these
gadget templates.
Place your screenshot here
Place your screenshot here
iPhone project
Show and explain your web, app
or software projects using these
gadget templates.
Place your screenshot here
Tablet project
Show and explain your web,
app or software projects
using these gadget
templates.
Place your screenshot here
Desktop project
Show and explain your web, app or software projects using these
gadget templates.
thanks!
Any questions?
You can find me at
@username
user@mail.me
Credits
Special thanks to all the people who made and
released these awesome resources for free:
▣ Presentation template by SlidesCarnival
▣ Photographs by Unsplash
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®
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:
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...
😉

More Related Content

Similar to Scala and Akka together - geek night jan 2017

Viola.pptxfdssffffdsfdfdsfsdfdsfsfsdfsdfdsfsd
Viola.pptxfdssffffdsfdfdsfsdfdsfsfsdfsdfdsfsdViola.pptxfdssffffdsfdfdsfsdfdsfsfsdfsdfdsfsd
Viola.pptxfdssffffdsfdfdsfsdfdsfsfsdfsdfdsfsdMinhHuyNguyen18
 
Chinese new year 2016 we rock the party
Chinese new year 2016 we  rock the partyChinese new year 2016 we  rock the party
Chinese new year 2016 we rock the partySona Bothare
 
Bussines Presentation Your score increases as you pick a category
Bussines Presentation Your score increases as you pick a categoryBussines Presentation Your score increases as you pick a category
Bussines Presentation Your score increases as you pick a categoryagim15
 
PPT Fonologi Kelompok 1.pptx
PPT Fonologi Kelompok 1.pptxPPT Fonologi Kelompok 1.pptx
PPT Fonologi Kelompok 1.pptxCeceOpenAi
 
presentation iti mind of map
presentation iti mind of mappresentation iti mind of map
presentation iti mind of mapAli Gamal
 
Dolabella primer nivel de la universidad
Dolabella primer nivel de la universidadDolabella primer nivel de la universidad
Dolabella primer nivel de la universidadluisvasconez10
 
Cordelia powerpoint style
Cordelia powerpoint styleCordelia powerpoint style
Cordelia powerpoint stylepyancey
 
Nathaniel.pptxfsdffsdfdgfdgdfgdfgdfgdfgdfgfdg
Nathaniel.pptxfsdffsdfdgfdgdfgdfgdfgdfgdfgfdgNathaniel.pptxfsdffsdfdgfdgdfgdfgdfgdfgdfgfdg
Nathaniel.pptxfsdffsdfdgfdgdfgdfgdfgdfgdfgfdgMinhHuyNguyen18
 
GeekNight 22.0 Multi-paradigm programming in Scala and Akka
GeekNight 22.0 Multi-paradigm programming in Scala and AkkaGeekNight 22.0 Multi-paradigm programming in Scala and Akka
GeekNight 22.0 Multi-paradigm programming in Scala and AkkaGeekNightHyderabad
 

Similar to Scala and Akka together - geek night jan 2017 (20)

Ophelia
OpheliaOphelia
Ophelia
 
Ariel.pptx
Ariel.pptxAriel.pptx
Ariel.pptx
 
Warwick
WarwickWarwick
Warwick
 
Fidele
FideleFidele
Fidele
 
Viola.pptxfdssffffdsfdfdsfsdfdsfsfsdfsdfdsfsd
Viola.pptxfdssffffdsfdfdsfsdfdsfsfsdfsdfdsfsdViola.pptxfdssffffdsfdfdsfsdfdsfsfsdfsdfdsfsd
Viola.pptxfdssffffdsfdfdsfsdfdsfsfsdfsdfdsfsd
 
Chinese new year 2016 we rock the party
Chinese new year 2016 we  rock the partyChinese new year 2016 we  rock the party
Chinese new year 2016 we rock the party
 
Bussines Presentation Your score increases as you pick a category
Bussines Presentation Your score increases as you pick a categoryBussines Presentation Your score increases as you pick a category
Bussines Presentation Your score increases as you pick a category
 
Balthasarwew
BalthasarwewBalthasarwew
Balthasarwew
 
Plantilla de powerpoint para usar gratis.
Plantilla de powerpoint para usar gratis.Plantilla de powerpoint para usar gratis.
Plantilla de powerpoint para usar gratis.
 
Minola · slides carnival
Minola · slides carnivalMinola · slides carnival
Minola · slides carnival
 
PPT Fonologi Kelompok 1.pptx
PPT Fonologi Kelompok 1.pptxPPT Fonologi Kelompok 1.pptx
PPT Fonologi Kelompok 1.pptx
 
Powerpoint Theme
Powerpoint ThemePowerpoint Theme
Powerpoint Theme
 
presentation iti mind of map
presentation iti mind of mappresentation iti mind of map
presentation iti mind of map
 
Dolabella primer nivel de la universidad
Dolabella primer nivel de la universidadDolabella primer nivel de la universidad
Dolabella primer nivel de la universidad
 
Palaamon.pptx
Palaamon.pptxPalaamon.pptx
Palaamon.pptx
 
Desdemona.pptx
Desdemona.pptxDesdemona.pptx
Desdemona.pptx
 
Cordelia powerpoint style
Cordelia powerpoint styleCordelia powerpoint style
Cordelia powerpoint style
 
Nathaniel.pptxfsdffsdfdgfdgdfgdfgdfgdfgdfgfdg
Nathaniel.pptxfsdffsdfdgfdgdfgdfgdfgdfgdfgfdgNathaniel.pptxfsdffsdfdgfdgdfgdfgdfgdfgdfgfdg
Nathaniel.pptxfsdffsdfdgfdgdfgdfgdfgdfgdfgfdg
 
GeekNight 22.0 Multi-paradigm programming in Scala and Akka
GeekNight 22.0 Multi-paradigm programming in Scala and AkkaGeekNight 22.0 Multi-paradigm programming in Scala and Akka
GeekNight 22.0 Multi-paradigm programming in Scala and Akka
 
Portia
PortiaPortia
Portia
 

Recently uploaded

Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
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...panagenda
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
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 Modelsaagamshah0812
 
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.pdfWave PLM
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
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.pdfkalichargn70th171
 
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.docxComplianceQuest1
 

Recently uploaded (20)

Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
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...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
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
 
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
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
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
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
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
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 

Scala and Akka together - geek night jan 2017

  • 2. Why not both? You really don’t have to choose just one.
  • 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?
  • 6. ➢ What is the Best code?
  • 7. ➢ What is the Best code? ○ The following =>
  • 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!
  • 9.
  • 10. ➢ Get all products from the orders
  • 11. ➢ Get all products from the orders Or
  • 12. ➢ Sort the products by Id Or
  • 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.
  • 14. ➢ Why learn Functional Programming ?
  • 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.
  • 16. ➢ How does FP improve code?
  • 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.
  • 20. ➢ What makes Scala functional ?
  • 21. ➢ Functions are 1st class citizens => ○ Instead =>
  • 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!
  • 26.
  • 27. String is referentially transparent and holds substitution model.
  • 28. ➢ Similarly, add() here is also without side-effects and referentially transparent.
  • 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.
  • 30. ➢ Just enough Scala for Akka.
  • 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.
  • 32. ➢ Pattern matching ○ Switch case on steroids
  • 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 =>
  • 35.
  • 36.
  • 37.
  • 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
  • 45. State
  • 47. Let’s look at an actor
  • 48. DEMO
  • 49. Scaling out in clusters
  • 50. Seperator The original template slides are below this slide
  • 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
  • 53. 1. Transition headline Let’s start with the first set of slides
  • 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.
  • 60. want big impact? Use big image
  • 61. Use charts to explain your ideas White BlackGray
  • 62. And tables to compare data A B C Yellow 10 20 7 Blue 30 15 10 Orange 5 24 16
  • 64. 89,526,124 Whoa! That’s a big number, aren’t you proud?
  • 65. 89,526,124$ That’s a lot of money 100% Total success! 185,244 users And a lot of users
  • 66. Our process is easy first second last
  • 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.
  • 68. You can copy&paste graphs from Google Sheets
  • 69. Android project Show and explain your web, app or software projects using these gadget templates. Place your screenshot here
  • 70. Place your screenshot here iPhone project Show and explain your web, app or software projects using these gadget templates.
  • 71. Place your screenshot here Tablet project Show and explain your web, app or software projects using these gadget templates.
  • 72. Place your screenshot here Desktop project Show and explain your web, app or software projects using these gadget templates.
  • 73. thanks! Any questions? You can find me at @username user@mail.me
  • 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

  1. 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.