SlideShare a Scribd company logo
FP 4 OOP FTW!
@KevlinHenney
Functional Programming
for Object-Oriented
Programming
– for the Win!
Kevlin Henney
FP 4 OOP FTW!
FP 4 OOP FTW!
FP 4 OOP FTW!
FP 4 OOP FTW!
functional
programming
higher-order functions
recursion
statelessness
first-class functions
immutability
pure functions
unification
declarative
pattern matching
non-strict evaluation
idempotence
lists
mathematics
lambdas
currying
monads
When it is not
necessary to
change, it is
necessary not
to change.
Lucius Cary
public class Date implements ...
{
...
public int getYear() ...
public int getMonth() ...
public int getDayInMonth() ...
public void setYear(int newYear) ...
public void setMonth(int newMonth) ...
public void setDayInMonth(int newDayInMonth) ...
...
}
public class Date implements ...
{
...
public int getYear() ...
public int getMonth() ...
public int getWeekInYear() ...
public int getDayInYear() ...
public int getDayInMonth() ...
public int getDayInWeek() ...
public void setYear(int newYear) ...
public void setMonth(int newMonth) ...
public void setWeekInYear(int newWeek) ...
public void setDayInYear(int newDayInYear) ...
public void setDayInMonth(int newDayInMonth) ...
public void setDayInWeek(int newDayInWeek) ...
...
}
public final class Date implements ...
{
...
public int getYear() ...
public int getMonth() ...
public int getWeekInYear() ...
public int getDayInYear() ...
public int getDayInMonth() ...
public int getDayInWeek() ...
...
}
public final class Date implements ...
{
...
public int year() ...
public int month() ...
public int weekInYear() ...
public int dayInYear() ...
public int dayInMonth() ...
public int dayInWeek() ...
...
}
FP 4 OOP FTW!
Immutable Value
References to value objects are commonly distributed and
stored in fields. However, state changes to a value caused
by one object can have unexpected and unwanted side-
effects for any other object sharing the same value
instance. Copying the value can reduce the
synchronization overhead, but can also incur object
creation overhead.
Therefore:
Define a value object type whose instances are immutable.
The internal state of a value object is set at construction
and no subsequent modifications are allowed.
public final class Date implements ...
{
...
public void nextDay() ...
public void addDays(int numberOfDays) ...
...
}
public final class Date implements ...
{
...
public Date nextDay() ...
public Date addDays(int numberOfDays) ...
...
}
public final class Date implements ...
{
...
public Date dayAfter() ...
public Date daysAdded(int numberOfDays) ...
...
}
FP 4 OOP FTW!
Referential transparency is a very
desirable property: it implies that
functions consistently yield the same
results given the same input,
irrespective of where and when they are
invoked. That is, function evaluation
depends less—ideally, not at all—on the
side effects of mutable state.
Edward Garson
"Apply Functional Programming Principles"
Idempotence is the property of certain operations in
mathematics and computer science, that they can
be applied multiple times without changing the
result beyond the initial application.
The concept of idempotence arises in a number of
places in abstract algebra [...] and functional
programming (in which it is connected to the
property of referential transparency).
http://en.wikipedia.org/wiki/Idempotent
Asking a question
should not change
the answer.
Bertrand Meyer
Asking a question
should not change
the answer, and
nor should asking
it twice!
Immutable Value
Define a value object type
whose instances are immutable.
Copied Value
Define a value object type
whose instances are copyable.
class date
{
public:
date(int year, int month, int day_in_month);
date(const date &);
date & operator=(const date &);
...
int year() const;
int month() const;
int day_in_month() const;
...
void year(int);
void month(int);
void day_in_month(int);
...
};
class date
{
public:
date(int year, int month, int day_in_month);
date(const date &);
date & operator=(const date &);
...
int year() const;
int month() const;
int day_in_month() const;
...
void set(int year, int month, int day_in_month);
...
};
today.set(2015, 3, 24);
class date
{
public:
date(int year, int month, int day_in_month);
date(const date &);
date & operator=(const date &);
...
int year() const;
int month() const;
int day_in_month() const;
...
};
today = date(2015, 3, 24);
FP 4 OOP FTW!
Many objects have no conceptual
identity. These objects describe
some characteristic of a thing.
When you care only about the
attributes of an element of the
model, classify it as a VALUE
OBJECT. Make it express the
meaning of the attributes it
conveys and give it related
functionality. Treat the VALUE
OBJECT as immutable. Don't give
it any identity and avoid the
design complexities necessary to
maintain ENTITIES.
LSP
A type hierarchy is composed of subtypes and
supertypes. The intuitive idea of a subtype is one
whose objects provide all the behavior of objects
of another type (the supertype) plus something
extra. What is wanted here is something like the
following substitution property: If for each
object o1 of type S there is an object o2 of type T
such that for all programs P defined in terms of T,
the behavior of P is unchanged when o1 is
substituted for o2, then S is a subtype of T.
Barbara Liskov
"Data Abstraction and Hierarchy"
A type hierarchy is composed of subtypes and
supertypes. The intuitive idea of a subtype is one
whose objects provide all the behavior of objects
of another type (the supertype) plus something
extra. What is wanted here is something like the
following substitution property: If for each
object o1 of type S there is an object o2 of type T
such that for all programs P defined in terms of T,
the behavior of P is unchanged when o1 is
substituted for o2, then S is a subtype of T.
Barbara Liskov
"Data Abstraction and Hierarchy"
A type hierarchy is composed of subtypes and
supertypes. The intuitive idea of a subtype is one
whose objects provide all the behavior of objects
of another type (the supertype) plus something
extra. What is wanted here is something like the
following substitution property: If for each
object o1 of type S there is an object o2 of type T
such that for all programs P defined in terms of T,
the behavior of P is unchanged when o1 is
substituted for o2, then S is a subtype of T.
Barbara Liskov
"Data Abstraction and Hierarchy"
public class Ellipse
{
private double semiMajor, semiMinor;
public Ellipse(double a, double b) ...
public double semiMajorAxis() ...
public double semiMinorAxis() ...
public void semiMajorAxis(double a) ...
public void semiMinorAxis(double b) ...
...
}
public class Circle extends Ellipse
{
public Circle(double r) ...
public double radius() ...
public void radius(double r) ...
...
}
public class Ellipse
{
...
public void semiMajorAxis(double a) ...
public void semiMinorAxis(double b) ...
...
}
public class Circle extends Ellipse
{
...
@Override
public void semiMajorAxis(double a)
{
throw new UnsupportedOperationException();
}
@Override
public void semiMinorAxis(double b) ...
...
}
The reason a solution is so hard to come by is because the
problem is poorly stated: mathematics tells us that a circle is an
ellipse, so I can substitute a circle wherever an ellipse is required,
suggesting that a circle is a subtype of an ellipse.
Kevlin Henney
"Vicious Circles", Overload 8, June 1995
The reason a solution is so hard to come by is because the
problem is poorly stated: mathematics tells us that a circle is an
ellipse, so I can substitute a circle wherever an ellipse is required,
suggesting that a circle is a subtype of an ellipse.
The troubles start when we introduce any state modifying
functions, such as assignment or the ability to change the major
and minor axes independently.
Kevlin Henney
"Vicious Circles", Overload 8, June 1995
The reason a solution is so hard to come by is because the
problem is poorly stated: mathematics tells us that a circle is an
ellipse, so I can substitute a circle wherever an ellipse is required,
suggesting that a circle is a subtype of an ellipse.
The troubles start when we introduce any state modifying
functions, such as assignment or the ability to change the major
and minor axes independently.
We are so confident that we understand the mathematical
concepts behind circles and ellipses that we have not bothered to
ask any more questions of that domain.
Kevlin Henney
"Vicious Circles", Overload 8, June 1995
The first observation is that there is no way to change circles and
ellipses once you have created them.
Kevlin Henney
"Vicious Circles", Overload 8, June 1995
The first observation is that there is no way to change circles and
ellipses once you have created them.
This is the correct mathematical model: there are no side effects
in maths, conic sections do not undergo state changes, and there
are no variables in the programming sense of the word.
Kevlin Henney
"Vicious Circles", Overload 8, June 1995
The first observation is that there is no way to change circles and
ellipses once you have created them.
This is the correct mathematical model: there are no side effects
in maths, conic sections do not undergo state changes, and there
are no variables in the programming sense of the word.
Readers who are comfortable and familiar with functional
programming and data flow models will recognise the approach.
Kevlin Henney
"Vicious Circles", Overload 8, June 1995
The first observation is that there is no way to change circles and
ellipses once you have created them.
This is the correct mathematical model: there are no side effects
in maths, conic sections do not undergo state changes, and there
are no variables in the programming sense of the word.
Readers who are comfortable and familiar with functional
programming and data flow models will recognise the approach.
In the case of circles and ellipses, the circle is simply an ellipse
with specialised invariants. There is no additional state and none
of the members of an ellipse need overriding as they apply
equally well to a circle.
Kevlin Henney
"Vicious Circles", Overload 8, June 1995
public class Ellipse
{
private double semiMajor, semiMinor;
public Ellipse(double a, double b) ...
public double semiMajorAxis() ...
public double semiMinorAxis() ...
...
}
public class Circle extends Ellipse
{
public Circle(double r) ...
public double radius() ...
...
}
«interface»
UsageInterface
CommonCode
ConcreteLeaf ConcreteLeaf
Pure Interface Layer
Interfaces may extend
interfaces, but there is no
implementation defined in
this layer.
Common Code Layer
Only abstract classes are
defined in this layer, possibly
with inheritance, factoring out
any common implementation.
Concrete Class Layer
Only concrete classes are
defined, and they do not
inherit from one another.
ConcreteLeaf
public interface Ellipse
{
double semiMajorAxis();
double semiMinorAxis();
...
}
public interface Circle extends Ellipse
{
double radius();
...
}
public class ??? implements Ellipse
{
private double semiMajorAxis, semiMinorAxis;
...
}
public class ??? implements Circle
{
private double radius;
...
}
public class ??? implements Ellipse
{
private double semiMajorAxis, semiMinorAxis;
...
}
public class ??? implements Circle
{
private double radius;
...
}
The Naming of Cats is a difficult matter,
It isn't just one of your holiday games;
You may think at first I'm as mad as a hatter
When I tell you, a cat must have THREE DIFFERENT NAMES.
[...]
But above and beyond there's still one name left over,
And that is the name that you never will guess;
The name that no human research can discover—
But THE CAT HIMSELF KNOWS, and will never confess.
[...]
T S Eliot
public class Ellipse
{
private double semiMajor, semiMinor;
public Ellipse(double a, double b) ...
public double semiMajorAxis() ...
public double semiMinorAxis() ...
...
}
public class Circle
{
private double radius;
public Circle(double r) ...
public double radius() ...
public Ellipse toEllipse() ...
...
}
public class Ellipse
{
private double semiMajor, semiMinor;
public Ellipse(double a, double b) ...
public double semiMajorAxis() ...
public double semiMinorAxis() ...
public boolean isCircle() ...
...
}
FP 4 OOP FTW!
phenomenon (plural: phenomena): An
element of what we can observe in the world.
Phenomena may be individuals or relations.
Individuals are entities, events, or values.
Relations are roles, states, or truths.
individual: An individual is a phenomenon that
can be named and is distinct from every other
individual: for example, the number 17, George
III, or Deep Blue's first move against Kasparov.
relationship: A kind of phenomenon. An
association among two or more individuals, for
example, Mother(Lucy, Joe). Also, generally, any
pattern or structure among phenomena of a
domain.
Events. An event is an individual happening, taking
place at some particular point in time. Each event is
indivisible and instantaneous.
Entities. An entity is an individual that persists over
time and can change its properties and states from one
point in time to another.
Values. A value is an intangible individual that exists
outside time and space, and is not subject to change.
States. A state is a relation among individual entities
and values; it can change over time.
Truths. A truth is a relation among individuals that
cannot possibly change over time.
Roles. A role is a relation between an event and
individuals that participate in it in a particular way.
In computing, a persistent data structure is a data structure
that always preserves the previous version of itself when it is
modified. Such data structures are effectively immutable, as
their operations do not (visibly) update the structure in-place,
but instead always yield a new updated structure.
http://en.wikipedia.org/wiki/Persistent_data_structure
(A persistent data structure is not a data structure committed
to persistent storage, such as a disk; this is a different and
unrelated sense of the word "persistent.")
public interface RecentlyUsedList
{
static final RecentlyUsedList nil = new Null();
boolean isEmpty();
int size();
String get(int index);
RecentlyUsedList add(String newItem);
RecentlyUsedList remove(String toRemove);
}
RecentlyUsedList list =
nil.add("Alice").add("Bob").add("Alice");
assert list.size() == 2;
assert list.get(0).equals("Alice");
assert list.get(1).equals("Bob");
class Null implements RecentlyUsedList
{
public boolean isEmpty()
{
return true;
}
public int size()
{
return 0;
}
public String get(int index)
{
throw new IndexOutOfBoundsException();
}
public RecentlyUsedList add(String newItem)
{
return new Link(newItem, this);
}
public RecentlyUsedList remove(String toRemove)
{
return this;
}
}
class Link implements RecentlyUsedList
{
private final RecentlyUsedList next;
private final String item;
private final int size;
Link(String head, RecentlyUsedList tail)
{
next = tail;
item = head;
size = tail.size() + 1;
}
public boolean isEmpty()
{
return false;
}
public int size()
{
return size;
}
public String get(int index)
{
return index == 0 ? item : next.get(index - 1);
}
public RecentlyUsedList add(String newItem)
{
RecentlyUsedList removed = remove(newItem);
return
removed == next ?
this : new Link(newItem, removed);
}
public RecentlyUsedList remove(String toRemove)
{
if(item.equals(toRemove))
{
return next;
}
else
{
RecentlyUsedList removed =
next.remove(toRemove);
return removed == next ?
this : new Link(item, removed);
}
}
}
FP 4 OOP FTW!
One of the most powerful mechanisms
for program structuring [...] is the block
and procedure concept.
A procedure which is capable of giving
rise to block instances which survive its
call will be known as a class; and the
instances will be known as objects of
that class.
A call of a class generates a new object
of that class.
Ole-Johan Dahl and C A R Hoare
"Hierarchical Program Structures"
public class HeatingSystem
{
public void turnOn() 
public void turnOff() 

}
public class Timer
{
public Timer(TimeOfDay toExpire, Runnable toDo) 
public void run() 
public void cancel() 

}
Timer on =
new Timer(
timeToTurnOn,
new Runnable()
{
public void run()
{
heatingSystem.turnOn();
}
});
Timer off =
new Timer(
timeToTurnOff,
new Runnable()
{
public void run()
{
heatingSystem.turnOff();
}
});
class Timer
{
public:
Timer(TimeOfDay toExpire, function<void()> toDo);
void Run();
void Cancel();
...
};
Timer on(
timeOn,
bind(&HeatingSystem::TurnOn, &heatingSystem));
Timer off(
timeOff,
bind(&HeatingSystem::TurnOff, &heatingSystem));
public class Timer
{
public Timer(TimeOfDay toExpire, Action toDo) ...
public void Run() ...
public void Cancel() ...
...
}
Timer on = new Timer(timeOn, heatingSystem.TurnOn);
Timer off = new Timer(timeOff, heatingSystem.TurnOff);
Timer on = new Timer(timeOn, heatingSystem::turnOn);
Timer off = new Timer(timeOff, heatingSystem::turnOff);
Timer on =
new Timer(timeOn, () => heatingSystem.TurnOn());
Timer off =
new Timer(timeOff, () => heatingSystem.TurnOff());
Timer on =
new Timer(timeOn, () -> heatingSystem.turnOn());
Timer off =
new Timer(timeOff, () -> heatingSystem.turnOff());
Timer on(
timeOn, [&]() { heatingSystem.TurnOn(); });
Timer off(
timeOff, [&]() { heatingSystem.TurnOff(); });
William Cook, "On Understanding Data Abstraction, Revisited"
FP 4 OOP FTW!
Pluggable Behavior
How do you parameterize the behavior
of an object?
Using Pluggable Behavior is a much
better solution than creating a hundred
different subclasses, each differing from
each other in only one or two methods.
For simple behavior changes, use a
Pluggable Selector. A Pluggable Block
gives you more flexibility.
Use procedure arguments to provide
flexibility in an interface.
This technique can greatly simplify
an interface, eliminating a jumble of
parameters that amount to a small
programming language.
Butler W Lampson
"Hints for Computer System Design"
If you have a procedure with
ten parameters, you probably
missed some.
Alan Perlis
A simple example is an enumeration
procedure that returns all the
elements of a set satisfying some
property. The cleanest interface
allows the client to pass a filter
procedure that tests for the property,
rather than defining a special
language of patterns or whatever.
Butler W Lampson
"Hints for Computer System Design"
FP 4 OOP FTW!
Enumeration Method
Some types of aggregate [...] have representations that do
not conveniently support Iterator-based traversal.
Similarly, using an Iterator approach to access the
elements of an aggregate that is shared between threads
can incur unnecessary overhead from repeated locking.
Therefore:
Bring the iteration inside the aggregate and encapsulate
it in a single enumeration method that is responsible for
complete traversal. Pass the task of the loop—the action
to be executed on each element of the aggregate—as an
argument to the enumeration method, and apply it to
each element in turn.
Lifecycle Callback
The lifecycle of some objects is simple: their clients
create them before they are used, they stay alive as
long as they are used, and they are disposed of by
their clients when no longer used. However, some
objects have a much more complex lifecycle, driven by
the needs and events of their component environment.
Therefore:
Define key lifecycle events as callbacks in an interface
that is supported by framework objects. The
framework uses the callbacks to control the objects’
lifecycle explicitly.
public interface IObservable<out T>
{
IDisposable Subscribe(IObserver<T> observer);
}
public interface IObserver<in T>
{
void OnCompleted();
void OnError(Exception error);
void OnNext(T value);
}
IDisposable subscription =
source.Subscribe(
value => handle element,
error => handle exception,
() => handle completion);
Observer
Consumer objects sometimes depend on the state of, or
data maintained by, another provider object. If the
state of the provider object changes without notice,
however, the state of the dependent consumer objects
can become inconsistent.
Therefore:
Define a change-propagation mechanism in which the
provider—known as the ‘subject’—notifies registered
consumers—known as the ‘observers’—whenever its
state changes, so that the notified observers can
perform whatever actions they deem necessary.
Event-Based,
Implicit Invocation
The idea behind implicit
invocation is that instead
of invoking a procedure
directly, a component can
announce (or broadcast)
one or more events. Other
components in the system
can register an interest in
an event by associating a
procedure with it.
Thus an announcement
"implicitly" causes the
invocation of procedures in
other modules.
FP 4 OOP FTW!
Concurrency
Concurrency
Threads
Concurrency
Threads
Locks
Some people, when confronted with a
problem, think, "I know, I'll use threads,"
and then two they hav erpoblesms.
Ned Batchelder
https://twitter.com/#!/nedbat/status/194873829825327104
Shared memory is like a canvas where
threads collaborate in painting images,
except that they stand on the opposite
sides of the canvas and use guns rather
than brushes. The only way they can
avoid killing each other is if they shout
"duck!" before opening fire.
Bartosz Milewski
"Functional Data Structures and Concurrency in C++"
http://bartoszmilewski.com/2013/12/10/functional-data-structures-and-concurrency-in-c/
Mutable
Immutable
Unshared Shared
Unshared mutable
data needs no
synchronisation
Unshared immutable
data needs no
synchronisation
Shared mutable
data needs
synchronisation
Shared immutable
data needs no
synchronisation
Instead of using threads and shared memory
as our programming model, we can use
processes and message passing. Process here
just means a protected independent state
with executing code, not necessarily an
operating system process.
Russel Winder
"Message Passing Leads to Better Scalability in Parallel Systems"
OOP to me means only messaging,
local retention and protection and
hiding of state-process, and
extreme late-binding of all things.
It can be done in Smalltalk and in
LISP. There are possibly other
systems in which this is possible,
but I'm not aware of them.
Alan Kay
Languages such as Erlang (and occam before
it) have shown that processes are a very
successful mechanism for programming
concurrent and parallel systems. Such
systems do not have all the synchronization
stresses that shared-memory, multithreaded
systems have.
Russel Winder
"Message Passing Leads to Better Scalability in Parallel Systems"
FP 4 OOP FTW!
Multithreading is just one
damn thing after, before, or
simultaneous with another.
Andrei Alexandrescu
Actor-based concurrency is
just one damn message after
another.
Sender Receiver A
Message 1Message 3
Receiver B
In response to a message that it receives, an actor
can make local decisions, create more actors, send
more messages, and determine how to respond to
the next message received.
http://en.wikipedia.org/wiki/Actor_model
Future
Services that are invoked concurrently on a component
may need to return a result to the calling client.
However, if the client does not block after calling the
service, continuing instead with its own computation,
the service’s result may not be available when the
client needs to use it.
Therefore:
Immediately return a ‘virtual’ data object—called a
future—to the client when it invokes a service. This
future [...] only provides a value to clients when the
computation is complete.
FP 4 OOP FTW!
FP 4 OOP FTW!

More Related Content

PDF
Object? You Keep Using that Word
PDF
SOLID Deconstruction
PDF
SOLID Deconstruction
PDF
Solid Deconstruction
PDF
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
PPT
Representing and Reasoning with Modular Ontologies (2007)
PPT
Introduction to logic and prolog - Part 1
PPT
Using uml for ontology construction a case study in agriculture
Object? You Keep Using that Word
SOLID Deconstruction
SOLID Deconstruction
Solid Deconstruction
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Representing and Reasoning with Modular Ontologies (2007)
Introduction to logic and prolog - Part 1
Using uml for ontology construction a case study in agriculture

What's hot (20)

PPT
Using UML for Ontology construction: a case study in Agriculture
PPT
Oop concept
PDF
2.oop concept
PDF
Oop.concepts
PPT
Artificial intelligence Prolog Language
PDF
OWL 2 Overview
PPT
A Semantic Importing Approach to Knowledge Reuse from Multiple Ontologies
PDF
EEE oops Vth semester viva questions with answer
PPTX
01. design pattern
PPTX
Jarrar: ORM in Description Logic
PPTX
The Awesome Python Class Part-4
PDF
Ai lecture 09(unit03)
PPTX
Polymorphism in Python
PPTX
Lecture 18
PDF
Utility Classes
PPTX
Why Java is not a purely object oriented language?
PPT
Object modeling
DOCX
Java interview questions
PDF
Advanced Programming _Abstract Classes vs Interfaces (Java)
PPTX
The Awesome Python Class Part-5
Using UML for Ontology construction: a case study in Agriculture
Oop concept
2.oop concept
Oop.concepts
Artificial intelligence Prolog Language
OWL 2 Overview
A Semantic Importing Approach to Knowledge Reuse from Multiple Ontologies
EEE oops Vth semester viva questions with answer
01. design pattern
Jarrar: ORM in Description Logic
The Awesome Python Class Part-4
Ai lecture 09(unit03)
Polymorphism in Python
Lecture 18
Utility Classes
Why Java is not a purely object oriented language?
Object modeling
Java interview questions
Advanced Programming _Abstract Classes vs Interfaces (Java)
The Awesome Python Class Part-5
Ad

Viewers also liked (17)

PDF
Programming with GUTs
PDF
The Error of Our Ways
PPT
Usp795details
PPTX
Chapter 7
PPTX
Chapter 11
DOCX
Analog Labs - Pharma job interview based Quality Assurance training
PPTX
Chapter 18
PPTX
Chapter 11 Bulk repackaging and non-sterile compounding
PPTX
Chapter 14
PPTX
Chapter 16
PPTX
Career pharmacy
PDF
DevOps Maturity Curve v5
PPT
Chapter 9 compounding
PPT
Role of the pharmacist in medication safety.
PPT
Scope of pharmacy
PPTX
Introduction to Pharmacy ( HistoPhar )
PPT
Pharmacy History
Programming with GUTs
The Error of Our Ways
Usp795details
Chapter 7
Chapter 11
Analog Labs - Pharma job interview based Quality Assurance training
Chapter 18
Chapter 11 Bulk repackaging and non-sterile compounding
Chapter 14
Chapter 16
Career pharmacy
DevOps Maturity Curve v5
Chapter 9 compounding
Role of the pharmacist in medication safety.
Scope of pharmacy
Introduction to Pharmacy ( HistoPhar )
Pharmacy History
Ad

Similar to FP 4 OOP FTW! (20)

PDF
Immutability FTW!
PDF
Lambda? You Keep Using that Letter
PDF
The Expression Problem - Part 1
PDF
Seven Ineffective Coding Habits of Many Programmers
PDF
Symmetry, Scala & Software -- Refresh Dublin October 2013
PDF
It Is Possible to Do Object-Oriented Programming in Java
PPTX
Design patterns with Kotlin
PDF
What's next in Julia
KEY
LISP: How I Learned To Stop Worrying And Love Parantheses
PDF
人工智慧與物聯網的創新與服務模式
PPTX
Object Oriented Principle&rsquo;s
PDF
Real World Haskell: Lecture 4
PDF
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
PDF
Lambda Calculus by Dustin Mulcahey
PDF
Planar Dynamical Systems Selected Classical Problems Yirong Liu
PDF
Planar Dynamical Systems Selected Classical Problems Yirong Liu
PDF
DEF CON 27 - workshop - EIGENTOURIST - hacking with monads
KEY
Exciting JavaScript - Part I
PPTX
Clean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
PPTX
ScalaDays 2013 Keynote Speech by Martin Odersky
Immutability FTW!
Lambda? You Keep Using that Letter
The Expression Problem - Part 1
Seven Ineffective Coding Habits of Many Programmers
Symmetry, Scala & Software -- Refresh Dublin October 2013
It Is Possible to Do Object-Oriented Programming in Java
Design patterns with Kotlin
What's next in Julia
LISP: How I Learned To Stop Worrying And Love Parantheses
人工智慧與物聯網的創新與服務模式
Object Oriented Principle&rsquo;s
Real World Haskell: Lecture 4
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
Lambda Calculus by Dustin Mulcahey
Planar Dynamical Systems Selected Classical Problems Yirong Liu
Planar Dynamical Systems Selected Classical Problems Yirong Liu
DEF CON 27 - workshop - EIGENTOURIST - hacking with monads
Exciting JavaScript - Part I
Clean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
ScalaDays 2013 Keynote Speech by Martin Odersky

More from Kevlin Henney (20)

PDF
Program with GUTs
PDF
The Case for Technical Excellence
PDF
Empirical Development
PDF
Lambda? You Keep Using that Letter
PDF
Get Kata
PDF
Procedural Programming: It’s Back? It Never Went Away
PDF
Structure and Interpretation of Test Cases
PDF
Agility ≠ Speed
PDF
Refactoring to Immutability
PDF
Old Is the New New
PDF
Turning Development Outside-In
PDF
Giving Code a Good Name
PDF
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
PDF
Thinking Outside the Synchronisation Quadrant
PDF
Code as Risk
PDF
Software Is Details
PDF
Game of Sprints
PDF
Good Code
PDF
Seven Ineffective Coding Habits of Many Programmers
PDF
Declarative Thinking, Declarative Practice
Program with GUTs
The Case for Technical Excellence
Empirical Development
Lambda? You Keep Using that Letter
Get Kata
Procedural Programming: It’s Back? It Never Went Away
Structure and Interpretation of Test Cases
Agility ≠ Speed
Refactoring to Immutability
Old Is the New New
Turning Development Outside-In
Giving Code a Good Name
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Thinking Outside the Synchronisation Quadrant
Code as Risk
Software Is Details
Game of Sprints
Good Code
Seven Ineffective Coding Habits of Many Programmers
Declarative Thinking, Declarative Practice

Recently uploaded (20)

PDF
Nekopoi APK 2025 free lastest update
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
ai tools demonstartion for schools and inter college
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
L1 - Introduction to python Backend.pptx
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PPTX
Online Work Permit System for Fast Permit Processing
PDF
System and Network Administraation Chapter 3
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Introduction to Artificial Intelligence
PDF
top salesforce developer skills in 2025.pdf
PDF
AI in Product Development-omnex systems
Nekopoi APK 2025 free lastest update
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Odoo Companies in India – Driving Business Transformation.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
ai tools demonstartion for schools and inter college
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
L1 - Introduction to python Backend.pptx
Design an Analysis of Algorithms II-SECS-1021-03
Navsoft: AI-Powered Business Solutions & Custom Software Development
ManageIQ - Sprint 268 Review - Slide Deck
Online Work Permit System for Fast Permit Processing
System and Network Administraation Chapter 3
How to Migrate SBCGlobal Email to Yahoo Easily
Introduction to Artificial Intelligence
top salesforce developer skills in 2025.pdf
AI in Product Development-omnex systems

FP 4 OOP FTW!

  • 1. FP 4 OOP FTW! @KevlinHenney
  • 7. functional programming higher-order functions recursion statelessness first-class functions immutability pure functions unification declarative pattern matching non-strict evaluation idempotence lists mathematics lambdas currying monads
  • 8. When it is not necessary to change, it is necessary not to change. Lucius Cary
  • 9. public class Date implements ... { ... public int getYear() ... public int getMonth() ... public int getDayInMonth() ... public void setYear(int newYear) ... public void setMonth(int newMonth) ... public void setDayInMonth(int newDayInMonth) ... ... }
  • 10. public class Date implements ... { ... public int getYear() ... public int getMonth() ... public int getWeekInYear() ... public int getDayInYear() ... public int getDayInMonth() ... public int getDayInWeek() ... public void setYear(int newYear) ... public void setMonth(int newMonth) ... public void setWeekInYear(int newWeek) ... public void setDayInYear(int newDayInYear) ... public void setDayInMonth(int newDayInMonth) ... public void setDayInWeek(int newDayInWeek) ... ... }
  • 11. public final class Date implements ... { ... public int getYear() ... public int getMonth() ... public int getWeekInYear() ... public int getDayInYear() ... public int getDayInMonth() ... public int getDayInWeek() ... ... }
  • 12. public final class Date implements ... { ... public int year() ... public int month() ... public int weekInYear() ... public int dayInYear() ... public int dayInMonth() ... public int dayInWeek() ... ... }
  • 14. Immutable Value References to value objects are commonly distributed and stored in fields. However, state changes to a value caused by one object can have unexpected and unwanted side- effects for any other object sharing the same value instance. Copying the value can reduce the synchronization overhead, but can also incur object creation overhead. Therefore: Define a value object type whose instances are immutable. The internal state of a value object is set at construction and no subsequent modifications are allowed.
  • 15. public final class Date implements ... { ... public void nextDay() ... public void addDays(int numberOfDays) ... ... }
  • 16. public final class Date implements ... { ... public Date nextDay() ... public Date addDays(int numberOfDays) ... ... }
  • 17. public final class Date implements ... { ... public Date dayAfter() ... public Date daysAdded(int numberOfDays) ... ... }
  • 19. Referential transparency is a very desirable property: it implies that functions consistently yield the same results given the same input, irrespective of where and when they are invoked. That is, function evaluation depends less—ideally, not at all—on the side effects of mutable state. Edward Garson "Apply Functional Programming Principles"
  • 20. Idempotence is the property of certain operations in mathematics and computer science, that they can be applied multiple times without changing the result beyond the initial application. The concept of idempotence arises in a number of places in abstract algebra [...] and functional programming (in which it is connected to the property of referential transparency). http://en.wikipedia.org/wiki/Idempotent
  • 21. Asking a question should not change the answer. Bertrand Meyer
  • 22. Asking a question should not change the answer, and nor should asking it twice!
  • 23. Immutable Value Define a value object type whose instances are immutable. Copied Value Define a value object type whose instances are copyable.
  • 24. class date { public: date(int year, int month, int day_in_month); date(const date &); date & operator=(const date &); ... int year() const; int month() const; int day_in_month() const; ... void year(int); void month(int); void day_in_month(int); ... };
  • 25. class date { public: date(int year, int month, int day_in_month); date(const date &); date & operator=(const date &); ... int year() const; int month() const; int day_in_month() const; ... void set(int year, int month, int day_in_month); ... }; today.set(2015, 3, 24);
  • 26. class date { public: date(int year, int month, int day_in_month); date(const date &); date & operator=(const date &); ... int year() const; int month() const; int day_in_month() const; ... }; today = date(2015, 3, 24);
  • 28. Many objects have no conceptual identity. These objects describe some characteristic of a thing.
  • 29. When you care only about the attributes of an element of the model, classify it as a VALUE OBJECT. Make it express the meaning of the attributes it conveys and give it related functionality. Treat the VALUE OBJECT as immutable. Don't give it any identity and avoid the design complexities necessary to maintain ENTITIES.
  • 30. LSP
  • 31. A type hierarchy is composed of subtypes and supertypes. The intuitive idea of a subtype is one whose objects provide all the behavior of objects of another type (the supertype) plus something extra. What is wanted here is something like the following substitution property: If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2, then S is a subtype of T. Barbara Liskov "Data Abstraction and Hierarchy"
  • 32. A type hierarchy is composed of subtypes and supertypes. The intuitive idea of a subtype is one whose objects provide all the behavior of objects of another type (the supertype) plus something extra. What is wanted here is something like the following substitution property: If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2, then S is a subtype of T. Barbara Liskov "Data Abstraction and Hierarchy"
  • 33. A type hierarchy is composed of subtypes and supertypes. The intuitive idea of a subtype is one whose objects provide all the behavior of objects of another type (the supertype) plus something extra. What is wanted here is something like the following substitution property: If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2, then S is a subtype of T. Barbara Liskov "Data Abstraction and Hierarchy"
  • 34. public class Ellipse { private double semiMajor, semiMinor; public Ellipse(double a, double b) ... public double semiMajorAxis() ... public double semiMinorAxis() ... public void semiMajorAxis(double a) ... public void semiMinorAxis(double b) ... ... } public class Circle extends Ellipse { public Circle(double r) ... public double radius() ... public void radius(double r) ... ... }
  • 35. public class Ellipse { ... public void semiMajorAxis(double a) ... public void semiMinorAxis(double b) ... ... } public class Circle extends Ellipse { ... @Override public void semiMajorAxis(double a) { throw new UnsupportedOperationException(); } @Override public void semiMinorAxis(double b) ... ... }
  • 36. The reason a solution is so hard to come by is because the problem is poorly stated: mathematics tells us that a circle is an ellipse, so I can substitute a circle wherever an ellipse is required, suggesting that a circle is a subtype of an ellipse. Kevlin Henney "Vicious Circles", Overload 8, June 1995
  • 37. The reason a solution is so hard to come by is because the problem is poorly stated: mathematics tells us that a circle is an ellipse, so I can substitute a circle wherever an ellipse is required, suggesting that a circle is a subtype of an ellipse. The troubles start when we introduce any state modifying functions, such as assignment or the ability to change the major and minor axes independently. Kevlin Henney "Vicious Circles", Overload 8, June 1995
  • 38. The reason a solution is so hard to come by is because the problem is poorly stated: mathematics tells us that a circle is an ellipse, so I can substitute a circle wherever an ellipse is required, suggesting that a circle is a subtype of an ellipse. The troubles start when we introduce any state modifying functions, such as assignment or the ability to change the major and minor axes independently. We are so confident that we understand the mathematical concepts behind circles and ellipses that we have not bothered to ask any more questions of that domain. Kevlin Henney "Vicious Circles", Overload 8, June 1995
  • 39. The first observation is that there is no way to change circles and ellipses once you have created them. Kevlin Henney "Vicious Circles", Overload 8, June 1995
  • 40. The first observation is that there is no way to change circles and ellipses once you have created them. This is the correct mathematical model: there are no side effects in maths, conic sections do not undergo state changes, and there are no variables in the programming sense of the word. Kevlin Henney "Vicious Circles", Overload 8, June 1995
  • 41. The first observation is that there is no way to change circles and ellipses once you have created them. This is the correct mathematical model: there are no side effects in maths, conic sections do not undergo state changes, and there are no variables in the programming sense of the word. Readers who are comfortable and familiar with functional programming and data flow models will recognise the approach. Kevlin Henney "Vicious Circles", Overload 8, June 1995
  • 42. The first observation is that there is no way to change circles and ellipses once you have created them. This is the correct mathematical model: there are no side effects in maths, conic sections do not undergo state changes, and there are no variables in the programming sense of the word. Readers who are comfortable and familiar with functional programming and data flow models will recognise the approach. In the case of circles and ellipses, the circle is simply an ellipse with specialised invariants. There is no additional state and none of the members of an ellipse need overriding as they apply equally well to a circle. Kevlin Henney "Vicious Circles", Overload 8, June 1995
  • 43. public class Ellipse { private double semiMajor, semiMinor; public Ellipse(double a, double b) ... public double semiMajorAxis() ... public double semiMinorAxis() ... ... } public class Circle extends Ellipse { public Circle(double r) ... public double radius() ... ... }
  • 44. «interface» UsageInterface CommonCode ConcreteLeaf ConcreteLeaf Pure Interface Layer Interfaces may extend interfaces, but there is no implementation defined in this layer. Common Code Layer Only abstract classes are defined in this layer, possibly with inheritance, factoring out any common implementation. Concrete Class Layer Only concrete classes are defined, and they do not inherit from one another. ConcreteLeaf
  • 45. public interface Ellipse { double semiMajorAxis(); double semiMinorAxis(); ... } public interface Circle extends Ellipse { double radius(); ... }
  • 46. public class ??? implements Ellipse { private double semiMajorAxis, semiMinorAxis; ... } public class ??? implements Circle { private double radius; ... }
  • 47. public class ??? implements Ellipse { private double semiMajorAxis, semiMinorAxis; ... } public class ??? implements Circle { private double radius; ... } The Naming of Cats is a difficult matter, It isn't just one of your holiday games; You may think at first I'm as mad as a hatter When I tell you, a cat must have THREE DIFFERENT NAMES. [...] But above and beyond there's still one name left over, And that is the name that you never will guess; The name that no human research can discover— But THE CAT HIMSELF KNOWS, and will never confess. [...] T S Eliot
  • 48. public class Ellipse { private double semiMajor, semiMinor; public Ellipse(double a, double b) ... public double semiMajorAxis() ... public double semiMinorAxis() ... ... } public class Circle { private double radius; public Circle(double r) ... public double radius() ... public Ellipse toEllipse() ... ... }
  • 49. public class Ellipse { private double semiMajor, semiMinor; public Ellipse(double a, double b) ... public double semiMajorAxis() ... public double semiMinorAxis() ... public boolean isCircle() ... ... }
  • 51. phenomenon (plural: phenomena): An element of what we can observe in the world. Phenomena may be individuals or relations. Individuals are entities, events, or values. Relations are roles, states, or truths. individual: An individual is a phenomenon that can be named and is distinct from every other individual: for example, the number 17, George III, or Deep Blue's first move against Kasparov. relationship: A kind of phenomenon. An association among two or more individuals, for example, Mother(Lucy, Joe). Also, generally, any pattern or structure among phenomena of a domain.
  • 52. Events. An event is an individual happening, taking place at some particular point in time. Each event is indivisible and instantaneous. Entities. An entity is an individual that persists over time and can change its properties and states from one point in time to another. Values. A value is an intangible individual that exists outside time and space, and is not subject to change. States. A state is a relation among individual entities and values; it can change over time. Truths. A truth is a relation among individuals that cannot possibly change over time. Roles. A role is a relation between an event and individuals that participate in it in a particular way.
  • 53. In computing, a persistent data structure is a data structure that always preserves the previous version of itself when it is modified. Such data structures are effectively immutable, as their operations do not (visibly) update the structure in-place, but instead always yield a new updated structure. http://en.wikipedia.org/wiki/Persistent_data_structure (A persistent data structure is not a data structure committed to persistent storage, such as a disk; this is a different and unrelated sense of the word "persistent.")
  • 54. public interface RecentlyUsedList { static final RecentlyUsedList nil = new Null(); boolean isEmpty(); int size(); String get(int index); RecentlyUsedList add(String newItem); RecentlyUsedList remove(String toRemove); } RecentlyUsedList list = nil.add("Alice").add("Bob").add("Alice"); assert list.size() == 2; assert list.get(0).equals("Alice"); assert list.get(1).equals("Bob");
  • 55. class Null implements RecentlyUsedList { public boolean isEmpty() { return true; } public int size() { return 0; } public String get(int index) { throw new IndexOutOfBoundsException(); } public RecentlyUsedList add(String newItem) { return new Link(newItem, this); } public RecentlyUsedList remove(String toRemove) { return this; } } class Link implements RecentlyUsedList { private final RecentlyUsedList next; private final String item; private final int size; Link(String head, RecentlyUsedList tail) { next = tail; item = head; size = tail.size() + 1; } public boolean isEmpty() { return false; } public int size() { return size; } public String get(int index) { return index == 0 ? item : next.get(index - 1); } public RecentlyUsedList add(String newItem) { RecentlyUsedList removed = remove(newItem); return removed == next ? this : new Link(newItem, removed); } public RecentlyUsedList remove(String toRemove) { if(item.equals(toRemove)) { return next; } else { RecentlyUsedList removed = next.remove(toRemove); return removed == next ? this : new Link(item, removed); } } }
  • 57. One of the most powerful mechanisms for program structuring [...] is the block and procedure concept. A procedure which is capable of giving rise to block instances which survive its call will be known as a class; and the instances will be known as objects of that class. A call of a class generates a new object of that class. Ole-Johan Dahl and C A R Hoare "Hierarchical Program Structures"
  • 58. public class HeatingSystem { public void turnOn()  public void turnOff()   } public class Timer { public Timer(TimeOfDay toExpire, Runnable toDo)  public void run()  public void cancel()   }
  • 59. Timer on = new Timer( timeToTurnOn, new Runnable() { public void run() { heatingSystem.turnOn(); } }); Timer off = new Timer( timeToTurnOff, new Runnable() { public void run() { heatingSystem.turnOff(); } });
  • 60. class Timer { public: Timer(TimeOfDay toExpire, function<void()> toDo); void Run(); void Cancel(); ... };
  • 61. Timer on( timeOn, bind(&HeatingSystem::TurnOn, &heatingSystem)); Timer off( timeOff, bind(&HeatingSystem::TurnOff, &heatingSystem));
  • 62. public class Timer { public Timer(TimeOfDay toExpire, Action toDo) ... public void Run() ... public void Cancel() ... ... }
  • 63. Timer on = new Timer(timeOn, heatingSystem.TurnOn); Timer off = new Timer(timeOff, heatingSystem.TurnOff);
  • 64. Timer on = new Timer(timeOn, heatingSystem::turnOn); Timer off = new Timer(timeOff, heatingSystem::turnOff);
  • 65. Timer on = new Timer(timeOn, () => heatingSystem.TurnOn()); Timer off = new Timer(timeOff, () => heatingSystem.TurnOff());
  • 66. Timer on = new Timer(timeOn, () -> heatingSystem.turnOn()); Timer off = new Timer(timeOff, () -> heatingSystem.turnOff());
  • 67. Timer on( timeOn, [&]() { heatingSystem.TurnOn(); }); Timer off( timeOff, [&]() { heatingSystem.TurnOff(); });
  • 68. William Cook, "On Understanding Data Abstraction, Revisited"
  • 70. Pluggable Behavior How do you parameterize the behavior of an object? Using Pluggable Behavior is a much better solution than creating a hundred different subclasses, each differing from each other in only one or two methods. For simple behavior changes, use a Pluggable Selector. A Pluggable Block gives you more flexibility.
  • 71. Use procedure arguments to provide flexibility in an interface. This technique can greatly simplify an interface, eliminating a jumble of parameters that amount to a small programming language. Butler W Lampson "Hints for Computer System Design"
  • 72. If you have a procedure with ten parameters, you probably missed some. Alan Perlis
  • 73. A simple example is an enumeration procedure that returns all the elements of a set satisfying some property. The cleanest interface allows the client to pass a filter procedure that tests for the property, rather than defining a special language of patterns or whatever. Butler W Lampson "Hints for Computer System Design"
  • 75. Enumeration Method Some types of aggregate [...] have representations that do not conveniently support Iterator-based traversal. Similarly, using an Iterator approach to access the elements of an aggregate that is shared between threads can incur unnecessary overhead from repeated locking. Therefore: Bring the iteration inside the aggregate and encapsulate it in a single enumeration method that is responsible for complete traversal. Pass the task of the loop—the action to be executed on each element of the aggregate—as an argument to the enumeration method, and apply it to each element in turn.
  • 76. Lifecycle Callback The lifecycle of some objects is simple: their clients create them before they are used, they stay alive as long as they are used, and they are disposed of by their clients when no longer used. However, some objects have a much more complex lifecycle, driven by the needs and events of their component environment. Therefore: Define key lifecycle events as callbacks in an interface that is supported by framework objects. The framework uses the callbacks to control the objects’ lifecycle explicitly.
  • 77. public interface IObservable<out T> { IDisposable Subscribe(IObserver<T> observer); } public interface IObserver<in T> { void OnCompleted(); void OnError(Exception error); void OnNext(T value); } IDisposable subscription = source.Subscribe( value => handle element, error => handle exception, () => handle completion);
  • 78. Observer Consumer objects sometimes depend on the state of, or data maintained by, another provider object. If the state of the provider object changes without notice, however, the state of the dependent consumer objects can become inconsistent. Therefore: Define a change-propagation mechanism in which the provider—known as the ‘subject’—notifies registered consumers—known as the ‘observers’—whenever its state changes, so that the notified observers can perform whatever actions they deem necessary.
  • 79. Event-Based, Implicit Invocation The idea behind implicit invocation is that instead of invoking a procedure directly, a component can announce (or broadcast) one or more events. Other components in the system can register an interest in an event by associating a procedure with it. Thus an announcement "implicitly" causes the invocation of procedures in other modules.
  • 84. Some people, when confronted with a problem, think, "I know, I'll use threads," and then two they hav erpoblesms. Ned Batchelder https://twitter.com/#!/nedbat/status/194873829825327104
  • 85. Shared memory is like a canvas where threads collaborate in painting images, except that they stand on the opposite sides of the canvas and use guns rather than brushes. The only way they can avoid killing each other is if they shout "duck!" before opening fire. Bartosz Milewski "Functional Data Structures and Concurrency in C++" http://bartoszmilewski.com/2013/12/10/functional-data-structures-and-concurrency-in-c/
  • 86. Mutable Immutable Unshared Shared Unshared mutable data needs no synchronisation Unshared immutable data needs no synchronisation Shared mutable data needs synchronisation Shared immutable data needs no synchronisation
  • 87. Instead of using threads and shared memory as our programming model, we can use processes and message passing. Process here just means a protected independent state with executing code, not necessarily an operating system process. Russel Winder "Message Passing Leads to Better Scalability in Parallel Systems"
  • 88. OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I'm not aware of them. Alan Kay
  • 89. Languages such as Erlang (and occam before it) have shown that processes are a very successful mechanism for programming concurrent and parallel systems. Such systems do not have all the synchronization stresses that shared-memory, multithreaded systems have. Russel Winder "Message Passing Leads to Better Scalability in Parallel Systems"
  • 91. Multithreading is just one damn thing after, before, or simultaneous with another. Andrei Alexandrescu
  • 92. Actor-based concurrency is just one damn message after another.
  • 93. Sender Receiver A Message 1Message 3 Receiver B In response to a message that it receives, an actor can make local decisions, create more actors, send more messages, and determine how to respond to the next message received. http://en.wikipedia.org/wiki/Actor_model
  • 94. Future Services that are invoked concurrently on a component may need to return a result to the calling client. However, if the client does not block after calling the service, continuing instead with its own computation, the service’s result may not be available when the client needs to use it. Therefore: Immediately return a ‘virtual’ data object—called a future—to the client when it invokes a service. This future [...] only provides a value to clients when the computation is complete.