Reactive Programming Enthusiasts Denver
Meetup Kickoff - “What is Reactive?”
Patrick Charles
Patrick Charles
https://github.com/pchuck
Summary
• What/Why Reactive?
• Key Features
• Functional Languages
• Scala - actors, concurrency, message passing
• Code
What is Reactive?
"The world is concurrent. Things in the world don’t share data. Things communicate with
messages. Things fail."
- Joe Armstrong (Erlang co-creator)
Why Reactive?
• Complexity and Scale
• single/multicore -> thousands of nodes
• single/multiple users -> millions
• Kbps -> Gbps
• seconds -> nanoseconds
Key Features of Reactive
• 0: Asynchronous - nonblocking and event-driven
• 1: Loosely coupled - message passing w/o shared state
Reactive Manifesto• “Event-Driven” - asynchronous, communication
with message passing
• “Scalable” - loose coupling, event-driven, location transparency
• “Resilient” - able to recover from failures: isolation and supervision
• “Responsive” - responds in a meaningful and timely fashion
What happened?• Imperative Programming
• Thinly veiled abstractions of the underlying and pervasive computing architecture
• Shared state and serial execution of instructions
• Thank, and blame, Alan Turing (1936) and Jon Von Neumann (1945)
Functional vs. Imperative• Imperative
• focus on steps or instructions and associated states
• computation is statements that change state
• Functional
• focus on composition and arrangement of functions
• computation is mathematical functions
• avoids state and mutable data
Lambda Calculus
• Emphasis on functions or “software” independent of the underlying hardware
• Variable binding and substitution
• Computation by substitution and reduction
• Anonymous functions == lambda expressions
Common Features of Functional Languages
• Immutability
• Message Passing
• Actors and Concurrency
• Composition
Reactive Constructs in Scala
• “Event-Driven” - case classes, pattern matching
• “Scalable” - actors, promises, futures
• “Resilience” - futures (may never return or might return success/failure primitives), options (case object for non-existent values), supervisors (via Akka)
Fractals
• simple definitions
• infinitely complex
• detailed at arbitrary scales
• self-similar
Case Classes
• Definitions of data-holding objects
• Immutable and dependent on constructor args
• Decomposed using pattern matching
!
Actors
• Encapsulated units of consistency
• Operate asynchronously
• Communicate by message passing
• scala - Reactor Trait: act() react {
Traits• Interfaces
• Class definitions with method signatures
• Allow partial implementation
!
!
!
Code
Resources• http://zeroturnaround.com/rebellabs/what-is-
lambda-calculus-and-why-should-you-care/
• http://www.scala-lang.org/old/node/242
• http://www.reactivemanifesto.org/
• https://github.com/pchuck/fractactor
• Coursera: Principles of Scala and Reactive Programming in Scala
Summary• Software is used to model and solve real-world problems
• The world is infinitely complex and unpredictable
• Functional or imperative?
• “Reactive” can mean many things
• Programming Style
• Methodology
• Application Architecture
• General goal is to reduce side-effects, scale, deal rationally with non-determinism and failures
Definitions• Lambda Expressions: ~anonymous functions
• Currying: transformation/simplification of complex functions: f(x, y) = y/x -> f(2, y) = y/2
• Closures: separation of environment and control in evaluation of functions. A Lambda Expression with free variables that are closed or bound.
• Partial Function: f: X ↛ Y computed for X’, over f: X' → Y, where X’ is a subset of X
• Concepts and Theory
• Scala, w/o Akka, all computation, theory
• Real-world Application - Mark
Segue
Reactive Future (talks)• Reactive NoSQL - ReactiveMongo, MongoDB clusters and
replicasets
• Data Visualization - Reactive rendering of complex and dynamic datasets with Scala and D3
• Horizontal Scale - Reactive load balancing and fault tolerance with Amazon AWS and Elastic Load Balancing
• Reactive tools and techniques in imperative languages: Java or C#
• Reactive programming in other functional languages: Erlang, Haskell, Clojure, F#, Lisp
• Interest areas, suggestions?