Go With the Flow:
A Reactive State of Mind
@colinmlee
Conclusion:
Complexity = BAD
Functions = SIMPLE
Who's This Guy?
Colin Lee
@colinmlee
Building Android team
@VidkuHQ,
makers of Flipgrid
30 years programming
Eyes Glazed Over?
Let's Stretch!
Simple ≠ Easy
Hate
Fear
Ignorance
We shouldn't need holy war to spread revolutionary ideas.
Want functional language depth?
See Brian Maddy's talk.
Looking for depth on RxJava?
See Dan Lew's talk.
I'm using short words.
I'm here recruiting for a language revolution.
Functions
Output
Input
No Side Effects
Reactive?
Output is a "Function" of Input

In Real-Time!
Reactive Programming is Functional Programming!
Your professor was right.
What problem does Rx solve?
CPUs Increasing

Cloud Increasing

Threading Code is Broken
- Locking & Synchronization
- Error Recovery
- Deadlocks
- Lifecycle Interruptions
- Retry
- Caching & Persistence
- Sharing State
- Callback Hell
- Negative Testing
Needless State Leads to Accidental Complexity
Chaining Functions Avoids Callback Hell
Threading Code is Broken
The old way is complex.
Ray Ozzie Memo
"Complexity kills!
It sucks the life
out of developers."
Conclusion:
Complexity = BAD
Functions = SIMPLE
Gang of Four
Gang Of Four
- Observer Pattern
- Iterator Pattern
- + Functional Programming
Jeff Atwood:
"Design patterns are a symptom that your language is broken."
Now I have a ProblemFactory.
I had a problem so I thought to use Java Design Patterns
"Boilerplate is a form of complexity."
Erik Meijer
"What's the difference between an array...
and events?"
Everything is a Stream
Some Deep Hippie Insight:
Is
2015
The Year of Functional Programming?
"Netflix is a big believer in the Rx model... it spreads deeper into our code the more we use it."

"If asynchronous spaghetti code were a disease, Rx is the cure.”

"[Our] desktop developers loved Rx so much that the Mac team created their own version."

Language Support
This all happened in two years!
Rx is now core Dart!
Is
2015
The Year of Functional Programming?
Seems so!
Java 8 Streams
List<Integer> numbers =
Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8);
numbers.stream()
.filter(num -> num > 4)
.map(num -> num * 10)
.forEach(System.out::println);
// outputs 50, 60, 70, 80Java 8 Streams
Apply Functions to Whole Arrays/Collections
RxJava
List<Integer> numbers =
Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8);
Observable.from(numbers)
.filter(num -> num > 4)
.map(num -> num * 10)
.subscribe(System.out::println);
// outputs 50, 60, 70, 80RxJava = Async Streams
RxJava
Observable<Result> dbResult =
numbersObservable
.flatMap(num -> database(num))
.filter(obj -> obj.newer(cacheExp);
Observable<Result> netResult =
numbersObservable
.flatMap(num -> network(
"http://example.com/" + num));
Observable.merge(dbResult, netResult)
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.trampoline())
.subscribe(System.out::println);
// outputs result of http://example.com/
// with paths of /50, /60, /70, /80RxJava
Apply Functions to Streams of Events
FRP
Functional Reactive Programming
Goes Beyond Rx
FRP
=
Pure
Rx is best of both worlds.
Time is Only a Variable
Some Deep Hippie Insight:
Time Travel is Easy!
Elm
main =
asText <<
List.map (\x->x*10) <|
List.filter (\x->x>4) [1..8]
-- prints 50, 60, 70, 80I changed history!
Now it's your turn.
Conclusion:
Complexity = BAD
Functions = SIMPLE
Questions?
Go With The Flow: A Reactive State of Mind
By Colin Lee
Go With The Flow: A Reactive State of Mind
- 889