SlideShare a Scribd company logo
1 of 27
Download to read offline
DEMYSTIFYING
REACTIVE
PROGRAMMING
Dr. Tom Bulatewicz – ExakTime, Inc.
Seattle CodeCamp – 9 September 2017
Blog article at medium.com/@tombcz
“Reactive Programming”
“WTF is Reactive Programming” by Evgeny Poberezkin
“Reactive” dates back to at least 1969
What is a
Reactive
System?
“accepts inputs, performs
transformations on them and
produces outputs”
“repeatedly prompted
by the outside world and
their role is to
continuously respond to
external inputs”
“On the development of reactive systems”, Harel and
Pnueli, 1985
vs.
Transformational
System
Reactive System Transformational
System
PNG
Image Converter
JPG
decode &
encode
temperature
Thermostat
on
< 65
off
Reactive
(Software)
Systems
Today refers to large software
systems as a whole
Parts of the system are decoupled
in space and time via message
passing
A reactive software system is a
group of reactive systems, each
responding to streams of
messages
Responsive
Message Driven
ResilientElastic
Value
Form
Means
www.reactivemanifesto.org
Reactive Program
The analog of message
passing in a system is
eventing in a program
Reactive System
Responsive
Event Driven
ResilientElastic
Value
Form
Means
Code
Code
Code
Code
Code
Code
streams of events
Modeling code components as reactive systems
Key Concept #1
Observation -
Decoupling
Code in Time
To model a piece of code
like a reactive system is to
give it the ability to respond
to other code
Some sort of observation –
like a callback, delegate,
event, etc.
Object A Object B
start observing
notify
notify
notify
stop observing
Observation
class A {
void processAll() {
while(b.hasItems()) {
process(b.next());
}
}
}
Class A
Class B
next() observe() notify()
class A {
public A() {
b.observe(this);
}
void notify(item) {
process(item);
}
}
Declarative vs.
Imperative
Reactive-style components
lend themselves to being
declarative
Say how things are, not how
to do them
5:00 Clock
Clock
5:00
5:00
“The time should be here”
Each second:
- Get the time
- Update the view
5:00
time?
Declarative Programming
1
2
3
4
A
5
4
= A1 + A2
B
Code Spreadsheet
var x = 5;
var y = 4;
var s <=> x + y; // s == 9
x = 9; // s == 13
do something
Reactive
Code
Other
Code
notify
Code reacts to streams of events
Key Concept #2
Benefits: Reduces dependencies & facilitates declarative code style
Where can we apply this?
User Interface Logic
Datastore
REST Client
Cloud
class ViewModel {
void update() {
var data = await restClient.Get();
dataStore.Save(data);
data = Logic(data);
UpdateUI(data);
}
}
User Interface
Datastore
REST Client
Cloud
ViewModel
Business
Logic
class ViewModel {
void notify(data) {
UpdateUI(data);
}
}
User Interface
Datastore
REST Client
Cloud
ViewModel
Business
Logic
Provider
notify()
ViewModel Provider
observe entity X
notify
notify
stop observing
update X
REST call and save
update X
REST call and save
View
Datastore
REST Client
Cloud
ViewModel
Business
Logic
Provider
notify()notify()
ViewModel Provider
observe entity X
notify
update X
View
bind property Y
notify
Anything (but not everything)
• Closely coupled
• Direct method calls
• Exchange mutable
objects
• Decoupled
• Observation
• Exchange immutable
objects
Reactive Extensions
■ Create observables and observe them
■ Manipulate the flow of events
Observer Observable
subscribe()
onNext()
Op
Example
var x = 5;
var y = 4;
var s <=> x + y; // s == 9
x = 9; // s == 13
var x = new Number { Value = 5 };
var y = new Number { Value = 4 };
var s = new Sum(x, y);
Console.WriteLine($"s={s.Value}");
x.Value = 9;
Console.WriteLine($"s={s.Value}");
https://goo.gl/gn3iTe
class Number
{
private int _value;
public int Value {
get { return _value; }
set { _value = value;
_subject.OnNext(_value); }
}
        private readonly Subject<int> _subject = new Subject<int>();
        public IObservable<int> Changed {
            get { return _subject.AsObservable(); }
        }
}
class Sum
{
private int _x;
private int _y;
private int _sum;
public int Value { get { return _sum; } }
        public Sum(Number x, Number y)
        {
_x = x.Value;
_y = y.Value;
            _sum = _x + _y;
            x.Changed.Subscribe((n) => { _x = n; _sum = _x + _y; });
            y.Changed.Subscribe((n) => { _y = n; _sum = _x + _y; });
        }
    }
RX Operators – Creation
Create an observable that emits a sequence of integers spaced by a
given time interval
Interval
Interval( x sec. )
x sec. x sec. x sec. x sec.
0 1 2 3
Suppress duplicate items emitted by an observable
Distinct
RX Operators – Filtering
1 2 2 1
1 2 3
3
Distinct
Transform the items emitted by an Observable by applying a function to
each of them
Map
RX Operators – Transformation
1 2 3
10 20 30
Map( x => 10 * x )
Combine multiple Observables into one by merging their emissions
Merge
RX Operators – Joining
20 40 60
Merge
1 1
80 100
20 40 60 80 1001 1
Summary
■ Reactive programming can be thought of as modeling code
as individual reactive systems
■ Decoupling code via observation reduces dependencies and
facilitates declarative programming
■ Reactive Extensions provide an implementation of the
Observer pattern along with operators
QUESTIONS?

More Related Content

What's hot

Reactive programming
Reactive programmingReactive programming
Reactive programmingsaykopatt
 
Reactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaReactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaNexThoughts Technologies
 
Reactive programming - Observable
Reactive programming - ObservableReactive programming - Observable
Reactive programming - ObservableDragos Ionita
 
How To Build, Integrate, and Deploy Real-Time Streaming Pipelines On Kubernetes
How To Build, Integrate, and Deploy Real-Time Streaming Pipelines On KubernetesHow To Build, Integrate, and Deploy Real-Time Streaming Pipelines On Kubernetes
How To Build, Integrate, and Deploy Real-Time Streaming Pipelines On KubernetesLightbend
 
Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive ProgrammingAndres Almiray
 
Full Stack Reactive In Practice
Full Stack Reactive In PracticeFull Stack Reactive In Practice
Full Stack Reactive In PracticeLightbend
 
Machine Learning At Speed: Operationalizing ML For Real-Time Data Streams
Machine Learning At Speed: Operationalizing ML For Real-Time Data StreamsMachine Learning At Speed: Operationalizing ML For Real-Time Data Streams
Machine Learning At Speed: Operationalizing ML For Real-Time Data StreamsLightbend
 
Functional reactive programming
Functional reactive programmingFunctional reactive programming
Functional reactive programmingHung Hoang
 
Grinding the java monolith
Grinding the java monolithGrinding the java monolith
Grinding the java monolithMichael Nygard
 
Enforcing Application SLA with Congress and Monasca
Enforcing Application SLA with Congress and MonascaEnforcing Application SLA with Congress and Monasca
Enforcing Application SLA with Congress and MonascaFabio Giannetti
 
Reactive Fast Data & the Data Lake with Akka, Kafka, Spark
Reactive Fast Data & the Data Lake with Akka, Kafka, SparkReactive Fast Data & the Data Lake with Akka, Kafka, Spark
Reactive Fast Data & the Data Lake with Akka, Kafka, SparkTodd Fritz
 
A Marriage of Lambda and Kappa: Supporting Iterative Development of an Event ...
A Marriage of Lambda and Kappa: Supporting Iterative Development of an Event ...A Marriage of Lambda and Kappa: Supporting Iterative Development of an Event ...
A Marriage of Lambda and Kappa: Supporting Iterative Development of an Event ...confluent
 
Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...
Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...
Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...Flink Forward
 
Lessons From HPE: From Batch To Streaming For 20 Billion Sensors With Lightbe...
Lessons From HPE: From Batch To Streaming For 20 Billion Sensors With Lightbe...Lessons From HPE: From Batch To Streaming For 20 Billion Sensors With Lightbe...
Lessons From HPE: From Batch To Streaming For 20 Billion Sensors With Lightbe...Lightbend
 
Pivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
Pivoting Spring XD to Spring Cloud Data Flow with Sabby AnandanPivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
Pivoting Spring XD to Spring Cloud Data Flow with Sabby AnandanPivotalOpenSourceHub
 
Designing and Implementing Information Systems with Event Modeling, Bobby Cal...
Designing and Implementing Information Systems with Event Modeling, Bobby Cal...Designing and Implementing Information Systems with Event Modeling, Bobby Cal...
Designing and Implementing Information Systems with Event Modeling, Bobby Cal...confluent
 
Building a Modern, Scalable Cyber Intelligence Platform with Apache Kafka | J...
Building a Modern, Scalable Cyber Intelligence Platform with Apache Kafka | J...Building a Modern, Scalable Cyber Intelligence Platform with Apache Kafka | J...
Building a Modern, Scalable Cyber Intelligence Platform with Apache Kafka | J...HostedbyConfluent
 

What's hot (20)

Reactive programming
Reactive programmingReactive programming
Reactive programming
 
Reactive programming intro
Reactive programming introReactive programming intro
Reactive programming intro
 
Reactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaReactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJava
 
Reactive programming - Observable
Reactive programming - ObservableReactive programming - Observable
Reactive programming - Observable
 
Project Reactor By Example
Project Reactor By ExampleProject Reactor By Example
Project Reactor By Example
 
How To Build, Integrate, and Deploy Real-Time Streaming Pipelines On Kubernetes
How To Build, Integrate, and Deploy Real-Time Streaming Pipelines On KubernetesHow To Build, Integrate, and Deploy Real-Time Streaming Pipelines On Kubernetes
How To Build, Integrate, and Deploy Real-Time Streaming Pipelines On Kubernetes
 
Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive Programming
 
Full Stack Reactive In Practice
Full Stack Reactive In PracticeFull Stack Reactive In Practice
Full Stack Reactive In Practice
 
Machine Learning At Speed: Operationalizing ML For Real-Time Data Streams
Machine Learning At Speed: Operationalizing ML For Real-Time Data StreamsMachine Learning At Speed: Operationalizing ML For Real-Time Data Streams
Machine Learning At Speed: Operationalizing ML For Real-Time Data Streams
 
Functional reactive programming
Functional reactive programmingFunctional reactive programming
Functional reactive programming
 
Grinding the java monolith
Grinding the java monolithGrinding the java monolith
Grinding the java monolith
 
Enforcing Application SLA with Congress and Monasca
Enforcing Application SLA with Congress and MonascaEnforcing Application SLA with Congress and Monasca
Enforcing Application SLA with Congress and Monasca
 
Reactive Fast Data & the Data Lake with Akka, Kafka, Spark
Reactive Fast Data & the Data Lake with Akka, Kafka, SparkReactive Fast Data & the Data Lake with Akka, Kafka, Spark
Reactive Fast Data & the Data Lake with Akka, Kafka, Spark
 
Uncoupling
UncouplingUncoupling
Uncoupling
 
A Marriage of Lambda and Kappa: Supporting Iterative Development of an Event ...
A Marriage of Lambda and Kappa: Supporting Iterative Development of an Event ...A Marriage of Lambda and Kappa: Supporting Iterative Development of an Event ...
A Marriage of Lambda and Kappa: Supporting Iterative Development of an Event ...
 
Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...
Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...
Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...
 
Lessons From HPE: From Batch To Streaming For 20 Billion Sensors With Lightbe...
Lessons From HPE: From Batch To Streaming For 20 Billion Sensors With Lightbe...Lessons From HPE: From Batch To Streaming For 20 Billion Sensors With Lightbe...
Lessons From HPE: From Batch To Streaming For 20 Billion Sensors With Lightbe...
 
Pivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
Pivoting Spring XD to Spring Cloud Data Flow with Sabby AnandanPivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
Pivoting Spring XD to Spring Cloud Data Flow with Sabby Anandan
 
Designing and Implementing Information Systems with Event Modeling, Bobby Cal...
Designing and Implementing Information Systems with Event Modeling, Bobby Cal...Designing and Implementing Information Systems with Event Modeling, Bobby Cal...
Designing and Implementing Information Systems with Event Modeling, Bobby Cal...
 
Building a Modern, Scalable Cyber Intelligence Platform with Apache Kafka | J...
Building a Modern, Scalable Cyber Intelligence Platform with Apache Kafka | J...Building a Modern, Scalable Cyber Intelligence Platform with Apache Kafka | J...
Building a Modern, Scalable Cyber Intelligence Platform with Apache Kafka | J...
 

Similar to Demystifying Reactive Programming

Programming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for AndroidProgramming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for AndroidEmanuele Di Saverio
 
Reactive programming every day
Reactive programming every dayReactive programming every day
Reactive programming every dayVadym Khondar
 
Rx 101 - Tamir Dresher - Copenhagen .NET User Group
Rx 101  - Tamir Dresher - Copenhagen .NET User GroupRx 101  - Tamir Dresher - Copenhagen .NET User Group
Rx 101 - Tamir Dresher - Copenhagen .NET User GroupTamir Dresher
 
Fuel Up JavaScript with Functional Programming
Fuel Up JavaScript with Functional ProgrammingFuel Up JavaScript with Functional Programming
Fuel Up JavaScript with Functional ProgrammingShine Xavier
 
2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & Webpack2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & WebpackCodifly
 
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016Trayan Iliev
 
Behavioral Design Patterns
Behavioral Design PatternsBehavioral Design Patterns
Behavioral Design PatternsLidan Hifi
 
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017Codemotion
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaRick Warren
 
JSAnkara Swift v React Native
JSAnkara Swift v React NativeJSAnkara Swift v React Native
JSAnkara Swift v React NativeMuhammed Demirci
 
Reactive Qt - Ivan Čukić (Qt World Summit 2015)
Reactive Qt - Ivan Čukić (Qt World Summit 2015)Reactive Qt - Ivan Čukić (Qt World Summit 2015)
Reactive Qt - Ivan Čukić (Qt World Summit 2015)Ivan Čukić
 
Akka with Scala
Akka with ScalaAkka with Scala
Akka with ScalaOto Brglez
 
ReactiveCocoa in Practice
ReactiveCocoa in PracticeReactiveCocoa in Practice
ReactiveCocoa in PracticeOutware Mobile
 
.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir Dresher.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir DresherTamir Dresher
 
NGRX Apps in Depth
NGRX Apps in DepthNGRX Apps in Depth
NGRX Apps in DepthTrayan Iliev
 
GDG Jakarta Meetup - Streaming Analytics With Apache Beam
GDG Jakarta Meetup - Streaming Analytics With Apache BeamGDG Jakarta Meetup - Streaming Analytics With Apache Beam
GDG Jakarta Meetup - Streaming Analytics With Apache BeamImre Nagi
 

Similar to Demystifying Reactive Programming (20)

Programming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for AndroidProgramming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for Android
 
Reactive programming every day
Reactive programming every dayReactive programming every day
Reactive programming every day
 
IKH331-07-java-rmi
IKH331-07-java-rmiIKH331-07-java-rmi
IKH331-07-java-rmi
 
Rx 101 - Tamir Dresher - Copenhagen .NET User Group
Rx 101  - Tamir Dresher - Copenhagen .NET User GroupRx 101  - Tamir Dresher - Copenhagen .NET User Group
Rx 101 - Tamir Dresher - Copenhagen .NET User Group
 
Rx workshop
Rx workshopRx workshop
Rx workshop
 
Rx – reactive extensions
Rx – reactive extensionsRx – reactive extensions
Rx – reactive extensions
 
Fuel Up JavaScript with Functional Programming
Fuel Up JavaScript with Functional ProgrammingFuel Up JavaScript with Functional Programming
Fuel Up JavaScript with Functional Programming
 
2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & Webpack2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & Webpack
 
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
 
DZone_RC_RxJS
DZone_RC_RxJSDZone_RC_RxJS
DZone_RC_RxJS
 
Behavioral Design Patterns
Behavioral Design PatternsBehavioral Design Patterns
Behavioral Design Patterns
 
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
 
JSAnkara Swift v React Native
JSAnkara Swift v React NativeJSAnkara Swift v React Native
JSAnkara Swift v React Native
 
Reactive Qt - Ivan Čukić (Qt World Summit 2015)
Reactive Qt - Ivan Čukić (Qt World Summit 2015)Reactive Qt - Ivan Čukić (Qt World Summit 2015)
Reactive Qt - Ivan Čukić (Qt World Summit 2015)
 
Akka with Scala
Akka with ScalaAkka with Scala
Akka with Scala
 
ReactiveCocoa in Practice
ReactiveCocoa in PracticeReactiveCocoa in Practice
ReactiveCocoa in Practice
 
.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir Dresher.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir Dresher
 
NGRX Apps in Depth
NGRX Apps in DepthNGRX Apps in Depth
NGRX Apps in Depth
 
GDG Jakarta Meetup - Streaming Analytics With Apache Beam
GDG Jakarta Meetup - Streaming Analytics With Apache BeamGDG Jakarta Meetup - Streaming Analytics With Apache Beam
GDG Jakarta Meetup - Streaming Analytics With Apache Beam
 

Recently uploaded

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 

Recently uploaded (20)

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 

Demystifying Reactive Programming

  • 1. DEMYSTIFYING REACTIVE PROGRAMMING Dr. Tom Bulatewicz – ExakTime, Inc. Seattle CodeCamp – 9 September 2017 Blog article at medium.com/@tombcz
  • 2. “Reactive Programming” “WTF is Reactive Programming” by Evgeny Poberezkin “Reactive” dates back to at least 1969
  • 3. What is a Reactive System? “accepts inputs, performs transformations on them and produces outputs” “repeatedly prompted by the outside world and their role is to continuously respond to external inputs” “On the development of reactive systems”, Harel and Pnueli, 1985 vs. Transformational System
  • 4. Reactive System Transformational System PNG Image Converter JPG decode & encode temperature Thermostat on < 65 off
  • 5. Reactive (Software) Systems Today refers to large software systems as a whole Parts of the system are decoupled in space and time via message passing A reactive software system is a group of reactive systems, each responding to streams of messages Responsive Message Driven ResilientElastic Value Form Means www.reactivemanifesto.org
  • 6. Reactive Program The analog of message passing in a system is eventing in a program Reactive System Responsive Event Driven ResilientElastic Value Form Means
  • 7. Code Code Code Code Code Code streams of events Modeling code components as reactive systems Key Concept #1
  • 8. Observation - Decoupling Code in Time To model a piece of code like a reactive system is to give it the ability to respond to other code Some sort of observation – like a callback, delegate, event, etc. Object A Object B start observing notify notify notify stop observing
  • 9. Observation class A { void processAll() { while(b.hasItems()) { process(b.next()); } } } Class A Class B next() observe() notify() class A { public A() { b.observe(this); } void notify(item) { process(item); } }
  • 10. Declarative vs. Imperative Reactive-style components lend themselves to being declarative Say how things are, not how to do them 5:00 Clock Clock 5:00 5:00 “The time should be here” Each second: - Get the time - Update the view 5:00 time?
  • 11. Declarative Programming 1 2 3 4 A 5 4 = A1 + A2 B Code Spreadsheet var x = 5; var y = 4; var s <=> x + y; // s == 9 x = 9; // s == 13
  • 12. do something Reactive Code Other Code notify Code reacts to streams of events Key Concept #2 Benefits: Reduces dependencies & facilitates declarative code style
  • 13. Where can we apply this? User Interface Logic Datastore REST Client Cloud
  • 14. class ViewModel { void update() { var data = await restClient.Get(); dataStore.Save(data); data = Logic(data); UpdateUI(data); } } User Interface Datastore REST Client Cloud ViewModel Business Logic
  • 15. class ViewModel { void notify(data) { UpdateUI(data); } } User Interface Datastore REST Client Cloud ViewModel Business Logic Provider notify() ViewModel Provider observe entity X notify notify stop observing update X REST call and save update X REST call and save
  • 17. Anything (but not everything) • Closely coupled • Direct method calls • Exchange mutable objects • Decoupled • Observation • Exchange immutable objects
  • 18. Reactive Extensions ■ Create observables and observe them ■ Manipulate the flow of events Observer Observable subscribe() onNext() Op
  • 19. Example var x = 5; var y = 4; var s <=> x + y; // s == 9 x = 9; // s == 13 var x = new Number { Value = 5 }; var y = new Number { Value = 4 }; var s = new Sum(x, y); Console.WriteLine($"s={s.Value}"); x.Value = 9; Console.WriteLine($"s={s.Value}"); https://goo.gl/gn3iTe
  • 20. class Number { private int _value; public int Value { get { return _value; } set { _value = value; _subject.OnNext(_value); } }         private readonly Subject<int> _subject = new Subject<int>();         public IObservable<int> Changed {             get { return _subject.AsObservable(); }         } }
  • 21. class Sum { private int _x; private int _y; private int _sum; public int Value { get { return _sum; } }         public Sum(Number x, Number y)         { _x = x.Value; _y = y.Value;             _sum = _x + _y;             x.Changed.Subscribe((n) => { _x = n; _sum = _x + _y; });             y.Changed.Subscribe((n) => { _y = n; _sum = _x + _y; });         }     }
  • 22. RX Operators – Creation Create an observable that emits a sequence of integers spaced by a given time interval Interval Interval( x sec. ) x sec. x sec. x sec. x sec. 0 1 2 3
  • 23. Suppress duplicate items emitted by an observable Distinct RX Operators – Filtering 1 2 2 1 1 2 3 3 Distinct
  • 24. Transform the items emitted by an Observable by applying a function to each of them Map RX Operators – Transformation 1 2 3 10 20 30 Map( x => 10 * x )
  • 25. Combine multiple Observables into one by merging their emissions Merge RX Operators – Joining 20 40 60 Merge 1 1 80 100 20 40 60 80 1001 1
  • 26. Summary ■ Reactive programming can be thought of as modeling code as individual reactive systems ■ Decoupling code via observation reduces dependencies and facilitates declarative programming ■ Reactive Extensions provide an implementation of the Observer pattern along with operators