1. The Joy of
Functional Programming
Jason Dew Mark Gunnels John Long
jason@catamorphiclabs.com mark@catamorphiclabs.com john@catamorphiclabs.com
2. About Us
Catamorphic Labs strives to create more
value than it takes by applying open source
software, emerging technology, and data analysis
to complex issues confronting organizations.
3. Agenda
Theory: why are we interested in
functional programming languages?
Praxis: demonstration of interesting
characteristics of functional languages
4. Theory
There is an impedance mismatch
between hardware and software
Current software paradigms are too
complex to be reasoned about easily
5. Brooks’ Thesis
No technology in the near future will
yield an order-of-magnitude
improvement in software productivity
“accidental complexity” eliminated
Only “essential complexity” remained
6. Brooks was right
Twenty years later and no order-of-
magnitude step has occurred in
mainstream software.
7. But...
Thesis was correct, assumptions were not
Several studies indicate that functional
programming may provide this increase
8. Case Study
Ericsson’s “Four-fold Increase in
Productivity and Quality” paper
A ten-fold reduction in lines of code
when C++ code was rewritten in Erlang
Defect count fell in proportion to the
lines of code
9. The Cause?
Suggests Erlang was removing
“accidental complexity” by reducing
the presence of:
Shared state
Side-effects
23. Erlang
Designed for scalability and reliability
Ericsson achieved 99.9999999% uptime
over the course of a year on a core router
Processes are very cheap in the Erlang VM
35. Solution? No Shared State
No locking needed, you don’t access the
same memory
Processes keep their own memory
(copies of what they need)
Changed something? Send a message.
36. Actor based Concurrency
In Erlang, processes are the actors
Each process has a mailbox
Processes communicate via message
passing
37. Actor based Concurrency
Send a process a message with the !
operator
Processes run on any processor or
computer
Able to run millions of processes inside
one virtual machine
54. STM
Analogous to database transactions for
controlling access to shared memory
Works with refs, a mutable type for
synchronous, coordinated changes to
one or more values
55. Atomic. Consistent. Isolated.
Updates are atomic
If you update more than one ref in a
transaction, the update appears as a
simultaneous event to everything
outside of the transaction
56. Atomic. Consistent. Isolated.
Updates are consistent
A new value can be checked with a
validator function before allowing the
transaction to commit
57. Atomic. Consistent. Isolated.
Updates are isolated
No transaction sees the effects of any
other transaction while it is running