Professional Documents
Culture Documents
Programación Scala: Carlos Andrés Méndez
Programación Scala: Carlos Andrés Méndez
Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018
Outline
▪ Review
▪ Functional programming
▪ Scala
▪ Scala Akka
Operating System Concepts – 10th Edition 4.2 Silberschatz, Galvin and Gagne ©2018
Functional programming
Operating System Concepts – 10th Edition 5.3 Silberschatz, Galvin and Gagne ©2018
Functional programming
Operating System Concepts – 10th Edition 5.4 Silberschatz, Galvin and Gagne ©2018
Functional programming
Operating System Concepts – 10th Edition 5.5 Silberschatz, Galvin and Gagne ©2018
Functional programming
Operating System Concepts – 10th Edition 5.6 Silberschatz, Galvin and Gagne ©2018
Example: Lisp programming language
Lisp
Programming
language
Originally specified in
1958
Multi-paradigm:
functional, procedural,
reflective, meta
Operating System Concepts – 10th Edition 5.7 Silberschatz, Galvin and Gagne ©2018
Functional programming: disadvantages
▪ Input–output is harder in a purely functional language.
▪ Functional programming languages have tended to be less efficient on
current hardware platforms.
• This is partly because current hardware platforms are not designed with
functional programming in mind.
• However, this has changed to a large extent with Scala and the
functional language Heskell.
▪ Not data oriented.
• Such data can be naturally represented via objects in an Object
Oriented language.
▪ Programmers are less familiar.
▪ Ivory tower languages.
Operating System Concepts – 10th Edition 5.8 Silberschatz, Galvin and Gagne ©2018
Example 2: Clojure programming language
Operating System Concepts – 10th Edition 5.9 Silberschatz, Galvin and Gagne ©2018
What Is Scala?
Operating System Concepts – 10th Edition 5.10 Silberschatz, Galvin and Gagne ©2018
Scala genealogy
Operating System Concepts – 10th Edition 5.11 Silberschatz, Galvin and Gagne ©2018
Scala genealogy: Prolog
Operating System Concepts – 10th Edition 5.12 Silberschatz, Galvin and Gagne ©2018
Scala documentation
Operating System Concepts – 10th Edition 5.13 Silberschatz, Galvin and Gagne ©2018
Scala features: Type inference
Operating System Concepts – 10th Edition 5.14 Silberschatz, Galvin and Gagne ©2018
Scala class vs Java class
Operating System Concepts – 10th Edition 5.15 Silberschatz, Galvin and Gagne ©2018
Scala class vs Java class
Operating System Concepts – 10th Edition 5.16 Silberschatz, Galvin and Gagne ©2018
Scala Akka
Operating System Concepts – 10th Edition 5.17 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 5.18 Silberschatz, Galvin and Gagne ©2018
Scala Akka
▪ Older versions of Scala also had their own scala.actor implementation of the
Actor model —however this is now deprecated and the recommendation is
to use the Akka implementation.
▪ These actors can hold their own state and behaviour. However, ideally only
immutable data is exchanged between them.
▪ The key idea underpinning the Actor model is that most of the problems with
concurrency, from deadlocks to data corruption, result from having shared
state.
Operating System Concepts – 10th Edition 5.19 Silberschatz, Galvin and Gagne ©2018
Actor model key principles
• No shared state.
• Lightweight processes.
• Asynchronous message passing.
• Buffering for incoming messages via an a inbox in which it receives messages.
• An actor can create other actors.
• No shared mutable data.
• No blocking operations.
• Any process can send a message to an actor.
• An actor does not do anything unless/until it receives a message.
Operating System Concepts – 10th Edition 5.20 Silberschatz, Galvin and Gagne ©2018
Actor model key principles
Messages are sent between actors and these messages are queued in an inbox in
a similar manner to email messages.
Operating System Concepts – 10th Edition 5.21 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 5.22 Silberschatz, Galvin and Gagne ©2018