SlideShare ist ein Scribd-Unternehmen logo
1 von 43
1SEC-2015
Reactive programming
every day
2SEC-2015
Who am I?
Vadym Khondar
Senior Software engineer
 8 years experience
 2.5 years with EPAM
Development team lead
Web, JavaScript, Java
vadym@khondar.name
3SEC-2015
Goals
Why to use
What is
How to use
reactive programming
4SEC-2015
Why?
5SEC-2015
Evolution of Internet
938 millions in June, 2004
3,035 millions in June, 2014
http://www.internetworldstats.com/emarketing.htm
1,440 millions in May, 2015
6SEC-2015
Evolution of expectations
• You see response to your actions quite quickly
• You don’t notice if something breaks
• You can collaborate
• You have everything you need at the place you are
7SEC-2015
1995 1997 1999 2001 2003 2005 2007 2009 2011 2013 2015
Evolution of challenges
Tens of servers
Seconds of response time
Hours of offline maintenance
Gigabytes of data
Millisecond response times
100% uptime
Cloud
Mobile devices
Internet of Things
8SEC-2015
Definition of reactive system
Reactive Systems are:
• Message-driven (react to events)
• Elastic (react to load)
• Resilient (react to failures)
• Responsive (react to users)
http://www.reactivemanifesto.org/
9SEC-2015
Why those qualities?
Responsive
Resilient
Message-
Driven
Elastic
Loose couplingLocation transparency
Responsive irrespectively to load Responsive irrespectively to failures
Asynchronous
10SEC-2015
So, if you still don’t
11SEC-2015
Tasks
We want our UI to not block.
We want our backend to not block.
* where it should not block
12SEC-2015
Reduce network latency influence
13SEC-2015
Events
14SEC-2015
Plain Old Observer pattern
15SEC-2015
1. Encapsulation principle may be violated
2. Separation of concerns principle may be violated
3. Not easily composable
4. Inversion of control
Observer pattern problems
16SEC-2015
$(function() {
var currentWord = '';
$('#textin').keypress(function(event) {
var key = String.fromCharCode(event.keyCode || event.charCode);
if (!key.match(/[w]/) && currentWord) {
var link = 'https://twitter.com/hashtag/' + currentWord;
$('#textout').append($(' ')).append(
$('<a/>').attr('href', link).text('#' + currentWord)
);
currentWord = '';
} else if (key) {
currentWord += key;
}
});
});
Example: Hash tagger
State
Mixing logic with
presentation
No easy way to
compose with
another handler of
keypress
17SEC-2015
Callback hell
public class ReportsEntryPoint {
@Override
public void onModuleLoad() {
String documentIdString = Window.Location.getParameter("docId");
if (documentIdString != null && !documentIdString.isEmpty()) {
try {
final Long documentId = Long.parseLong(documentIdString);
MainService.Util.getInstance().findReport(documentId, new AsyncCallback<ReportDto>() {
// Getting Report information first
@Override
public void onSuccess(ReportDto result) {
final ReportDto processedReport = result;
MainService.Util.getInstance().getUserInfo(processedReport.getUserId(), processedReport.getCompanyId(),
new AsyncCallback<UserCompanyDto>() {
// Getting user information for future form initialization
@Override
public void onSuccess(UserCompanyDto result) {
UserDataHolder.getInstance().setUserCompanyDto(result);
MainService.Util.getInstance().getDProfile(processedReport.getCompanyId(), new AsyncCallback<DProfileDto>() {
// Getting company profile for future form initialization
@Override
public void onSuccess(DProfileDto result) {
UserDataHolder.getInstance().setDProfileDto(result);
MainService.Util.getInstance().getPProfile(processedReport.getCompanyId(), new AsyncCallback<PProfileDto>() {
// Getting company profile for future form initialization
@Override
public void onSuccess(PProfileDto result) {
UserDataHolder.getInstance().setPProfileDto(result);
MainService.Util.getInstance().getFormDto(processedReport, new AsyncCallback<FormDTO>() {
// Getting report document form
@Override
public void onFailure(Throwable caught) {
Window.alert("Can't get document: " + caught.getMessage());
ReportEditorEntryPoint.windowClose();
}
@Override
public void onSuccess(FormDTO result) {
if (result == null) {
Window.alert("Can't get document.");
ReportEditorEntryPoint.windowClose();
return;
}
// -- some code to process if finally everything is ok!
}
})
http://callbackhell.com
18SEC-2015
Goods
// handling single value
Optional<Double> amount = Optional.of(1.0);
int roundedAmount = amount.orElse(2.0).intValue();
// handling multiple values
Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
.filter(i -> i % 2 == 0).skip(1).limit(2).forEachOrdered(System.out::println);
19SEC-2015
List<String> yellowFruits = new LinkedList<>();
for (String fruit : fruits) {
if (fruit.toLowerCase().contains("yellow")) {
yellowFruits.add(fruit);
}
}
Collections.sort(yellowFruits);
for (String fruit : yellowFruits) {
System.out.println(fruit);
}
fruits.stream()
.filter(f -> f.toLowerCase().contains("yellow"))
.sorted()
.forEach(System.out::println);
20SEC-2015
But…
Pulling
Pushing
21SEC-2015
22SEC-2015
Definition
Reactive programming is paradigm oriented
around data flows and propagation of change.
http://en.wikipedia.org/wiki/Reactive_programming
23SEC-2015
Reactive programming approach
Provide handy abstractions:
• Events and Event streams
• Behaviors
24SEC-2015
Event stream transformation
‘E’ pressed
‘p’ pressed
‘a’ pressed
‘m’ pressed
69
112
97
109
map()
•e ->
e.charCode
25SEC-2015
combine() – stream containing events from either combined streams
concat() – stream containing items of first stream and then of another stream
Stream transformation
map(Type1 => Type2) – stream of values from given function applied to each element in source stream
filter(Type => Boolean) – stream of values from source stream for which given function returns True
reduce((Type1, Type2) => Type1) (or scan(Fn, seed)) – stream of single value which is result of applying
given function to element in source stream and result of previous call to given function
skip(num) – stream produced from source stream by skipping num elements
take(num) – stream produced from source stream by taking num first elements
Transforming
Combining
26SEC-2015
Example: Hash tagger reactive
No global state
Clear separation of concerns
Declarative description
$(function () {
var keyStream = Rx.Observable.fromEvent($('#textin'), 'keypress')
.map(function (event) {
return String.fromCharCode(event.keyCode || event.charCode);
});
var endOfWordStream = keyStream.filter(function (char) {
return !String(char).match(/[w]/);
});
var wordStream = keyStream.buffer(endOfWordStream);
var uiUpdater = Rx.Observer.create(function (word) {
word = word.join('').trim();
var link = 'https://twitter.com/hashtag/' + word;
$('#textout').append($(' ')).append(
$('<a/>').attr('href', link).text('#' + word)
);
});
wordStream.subscribe(uiUpdater);
});
Composable API
27SEC-2015
Behavior (Signal)
Behaviors are used to express continuous dependency between values.
They are often referred to as function from time domain to value domain.
They are also called signals or properties.
Example:
𝛼 = 90 - minute x 6 angle of minute arrow on the clock
28SEC-2015
Signal <> Event
29SEC-2015
Example: Arkanoid
30SEC-2015
Example: Arkanoid – using property for mouse control
// some constants
var canvasLeft = $('#gamecanvas').offset().left + window.screenX;
var canvasRight = canvasLeft + $('#gamecanvas').width();
var canvasMid = (canvasRight + canvasLeft) / 2;
// define event stream for mouse movement
var mousePos = $('html')
.asEventStream('mousemove')
.map(function (event) {
return {x: event.screenX, y: event.screenY};
});
// define paddle position as a property in terms of mouse – stateless computation
var vausPos = mousePos.map(function (canvasLeft, canvasMid, canvasRight, coords) {
return ((coords.x < canvasLeft || coords.x > (canvasRight - 40))
? (coords.x < canvasMid ? canvasLeft : (canvasRight - 40))
: coords.x) - canvasLeft;
}, canvasLeft, canvasMid, canvasRight).toProperty();
// tie property to presentation
vausPos.assign($('#vaus'), 'css', 'left');
31SEC-2015
Futures and promises
Promise Future
Deferred PromiseJavaScript
Scala
CompletableFutureJava 8
Single write Multiple read
32SEC-2015
Producer Consumer
import scala.concurrent.{ future, promise }
import scala.concurrent.ExecutionContext.Implicits.global
val p = promise[T]
val f = p.future
val producer = future { // async
val r = produceSomething()
p success r // completion of future
scontinueDoingSomethingUnrelated()
}
val consumer = future { // async
startDoingSomething()
f onSuccess { // what to do on completion
case r => doSomethingWithResult()
}
}
33SEC-2015
Single item Many items
Pull/
Synchronous
Optional
Iterator/
Iterable
Push/
Asynchronous
Future
Observer/
Observable
34SEC-2015
Reactive programming
Benefits
• gives you a base for
creating reactive systems
• gives you means of
handling async in more
elegant way
• stimulates you to write
more concise code
Drawbacks
• might be harder do
debug
35SEC-2015
36SEC-2015
Think about
how data should flow
instead of
what you do to make it flow
37SEC-2015
Designing your API consider
making it asynchronous
38SEC-2015
Get acquainted with
functional programming
39SEC-2015
• Rx JS (http://reactivex.io/) – Observable on steroids
• Bacon.js (https://baconjs.github.io/) – EventStreams and
Properties (behaviors)
• Kefir.js (https://rpominov.github.io/kefir/) - inspired by Bacon.js
and RxJS with focus on high performance and low memory usage
Tools - Frontend
40SEC-2015
• Java 8 (hello to Streams, lambdas, CompletableFuture)
• Scala (gives a good taste of functional paradigm while letting you
have old habits)
• RxJava (https://github.com/ReactiveX/RxJava/)
Tools - Backend
41SEC-2015
References
• http://en.wikipedia.org/wiki/Reactive_programming
• http://en.wikipedia.org/wiki/Dataflow_programming
• http://www.reactivemanifesto.org/
• https://github.com/Reactive-Extensions/RxJS
• https://baconjs.github.io/
• What does it mean to be reactive by Erik Meijer
https://www.youtube.com/watch?v=sTSQlYX5DU0
• http://www.infoq.com/presentations/Netflix-API-rxjava-
hystrix/
• https://gist.github.com/staltz/868e7e9bc2a7b8c1f754
42SEC-2015
43SEC-2015
Code Presentation
https://goo.gl/BlJSCy http://goo.gl/suJ2Xg

Weitere ähnliche Inhalte

Was ist angesagt?

Enterprise State Management with NGRX/platform
Enterprise State Management with NGRX/platformEnterprise State Management with NGRX/platform
Enterprise State Management with NGRX/platformIlia Idakiev
 
Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6Ignacio Martín
 
Functional UIs with Java 8 and Vaadin JavaOne2014
Functional UIs with Java 8 and Vaadin JavaOne2014Functional UIs with Java 8 and Vaadin JavaOne2014
Functional UIs with Java 8 and Vaadin JavaOne2014hezamu
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVMVaclav Pech
 
Pick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitPick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitVaclav Pech
 
Akka: Actor Design & Communication Technics
Akka: Actor Design & Communication TechnicsAkka: Actor Design & Communication Technics
Akka: Actor Design & Communication TechnicsAlex Fruzenshtein
 
Best Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IVBest Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IVICS
 
Practical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme ChangePractical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme ChangeBurkhard Stubert
 
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)Ontico
 
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...Chris Richardson
 
Data in Motion: Streaming Static Data Efficiently
Data in Motion: Streaming Static Data EfficientlyData in Motion: Streaming Static Data Efficiently
Data in Motion: Streaming Static Data EfficientlyMartin Zapletal
 
Architecture for scalable Angular applications (with introduction and extende...
Architecture for scalable Angular applications (with introduction and extende...Architecture for scalable Angular applications (with introduction and extende...
Architecture for scalable Angular applications (with introduction and extende...Paweł Żurowski
 
Best Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part IIBest Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part IIICS
 

Was ist angesagt? (20)

Enterprise State Management with NGRX/platform
Enterprise State Management with NGRX/platformEnterprise State Management with NGRX/platform
Enterprise State Management with NGRX/platform
 
Firebase ng2 zurich
Firebase ng2 zurichFirebase ng2 zurich
Firebase ng2 zurich
 
Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6
 
Rxjs marble-testing
Rxjs marble-testingRxjs marble-testing
Rxjs marble-testing
 
Functional UIs with Java 8 and Vaadin JavaOne2014
Functional UIs with Java 8 and Vaadin JavaOne2014Functional UIs with Java 8 and Vaadin JavaOne2014
Functional UIs with Java 8 and Vaadin JavaOne2014
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
 
Pick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitPick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruit
 
Akka: Actor Design & Communication Technics
Akka: Actor Design & Communication TechnicsAkka: Actor Design & Communication Technics
Akka: Actor Design & Communication Technics
 
Best Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IVBest Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IV
 
Practical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme ChangePractical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme Change
 
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
 
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
 
J Query Presentation of David
J Query Presentation of DavidJ Query Presentation of David
J Query Presentation of David
 
Data in Motion: Streaming Static Data Efficiently
Data in Motion: Streaming Static Data EfficientlyData in Motion: Streaming Static Data Efficiently
Data in Motion: Streaming Static Data Efficiently
 
Architecture for scalable Angular applications (with introduction and extende...
Architecture for scalable Angular applications (with introduction and extende...Architecture for scalable Angular applications (with introduction and extende...
Architecture for scalable Angular applications (with introduction and extende...
 
Ngrx slides
Ngrx slidesNgrx slides
Ngrx slides
 
Angular mix chrisnoring
Angular mix chrisnoringAngular mix chrisnoring
Angular mix chrisnoring
 
Best Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part IIBest Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part II
 
Writing Good Tests
Writing Good TestsWriting Good Tests
Writing Good Tests
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 

Ähnlich wie Reactive programming every day

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
 
Apache Spark Streaming: Architecture and Fault Tolerance
Apache Spark Streaming: Architecture and Fault ToleranceApache Spark Streaming: Architecture and Fault Tolerance
Apache Spark Streaming: Architecture and Fault ToleranceSachin Aggarwal
 
Declarative presentations UIKonf
Declarative presentations UIKonfDeclarative presentations UIKonf
Declarative presentations UIKonfNataliya Patsovska
 
Futures and Rx Observables: powerful abstractions for consuming web services ...
Futures and Rx Observables: powerful abstractions for consuming web services ...Futures and Rx Observables: powerful abstractions for consuming web services ...
Futures and Rx Observables: powerful abstractions for consuming web services ...Chris Richardson
 
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageabilityDaniel Fisher
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSam Brannen
 
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
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsFrancois Zaninotto
 
Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30) Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30) Paco de la Cruz
 
Promises are so passé - Tim Perry - Codemotion Milan 2016
Promises are so passé - Tim Perry - Codemotion Milan 2016Promises are so passé - Tim Perry - Codemotion Milan 2016
Promises are so passé - Tim Perry - Codemotion Milan 2016Codemotion
 
React & The Art of Managing Complexity
React &  The Art of Managing ComplexityReact &  The Art of Managing Complexity
React & The Art of Managing ComplexityRyan Anklam
 
Применение паттерна Page Object для автоматизации веб сервисов
Применение паттерна Page Object для автоматизации веб сервисовПрименение паттерна Page Object для автоматизации веб сервисов
Применение паттерна Page Object для автоматизации веб сервисовCOMAQA.BY
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy codeShriKant Vashishtha
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade ServerlessKatyShimizu
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade ServerlessKatyShimizu
 
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMohammad Shaker
 
Unit test candidate solutions
Unit test candidate solutionsUnit test candidate solutions
Unit test candidate solutionsbenewu
 

Ähnlich wie Reactive programming every day (20)

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
 
Rx workshop
Rx workshopRx workshop
Rx workshop
 
Apache Spark Streaming: Architecture and Fault Tolerance
Apache Spark Streaming: Architecture and Fault ToleranceApache Spark Streaming: Architecture and Fault Tolerance
Apache Spark Streaming: Architecture and Fault Tolerance
 
Declarative presentations UIKonf
Declarative presentations UIKonfDeclarative presentations UIKonf
Declarative presentations UIKonf
 
Clean Architecture @ Taxibeat
Clean Architecture @ TaxibeatClean Architecture @ Taxibeat
Clean Architecture @ Taxibeat
 
Futures and Rx Observables: powerful abstractions for consuming web services ...
Futures and Rx Observables: powerful abstractions for consuming web services ...Futures and Rx Observables: powerful abstractions for consuming web services ...
Futures and Rx Observables: powerful abstractions for consuming web services ...
 
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
 
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
 
mobl
moblmobl
mobl
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
 
Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30) Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30)
 
Promises are so passé - Tim Perry - Codemotion Milan 2016
Promises are so passé - Tim Perry - Codemotion Milan 2016Promises are so passé - Tim Perry - Codemotion Milan 2016
Promises are so passé - Tim Perry - Codemotion Milan 2016
 
React & The Art of Managing Complexity
React &  The Art of Managing ComplexityReact &  The Art of Managing Complexity
React & The Art of Managing Complexity
 
Применение паттерна Page Object для автоматизации веб сервисов
Применение паттерна Page Object для автоматизации веб сервисовПрименение паттерна Page Object для автоматизации веб сервисов
Применение паттерна Page Object для автоматизации веб сервисов
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy code
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
 
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhone
 
Unit test candidate solutions
Unit test candidate solutionsUnit test candidate solutions
Unit test candidate solutions
 

Kürzlich hochgeladen

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Kürzlich hochgeladen (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Reactive programming every day

  • 2. 2SEC-2015 Who am I? Vadym Khondar Senior Software engineer  8 years experience  2.5 years with EPAM Development team lead Web, JavaScript, Java vadym@khondar.name
  • 3. 3SEC-2015 Goals Why to use What is How to use reactive programming
  • 5. 5SEC-2015 Evolution of Internet 938 millions in June, 2004 3,035 millions in June, 2014 http://www.internetworldstats.com/emarketing.htm 1,440 millions in May, 2015
  • 6. 6SEC-2015 Evolution of expectations • You see response to your actions quite quickly • You don’t notice if something breaks • You can collaborate • You have everything you need at the place you are
  • 7. 7SEC-2015 1995 1997 1999 2001 2003 2005 2007 2009 2011 2013 2015 Evolution of challenges Tens of servers Seconds of response time Hours of offline maintenance Gigabytes of data Millisecond response times 100% uptime Cloud Mobile devices Internet of Things
  • 8. 8SEC-2015 Definition of reactive system Reactive Systems are: • Message-driven (react to events) • Elastic (react to load) • Resilient (react to failures) • Responsive (react to users) http://www.reactivemanifesto.org/
  • 9. 9SEC-2015 Why those qualities? Responsive Resilient Message- Driven Elastic Loose couplingLocation transparency Responsive irrespectively to load Responsive irrespectively to failures Asynchronous
  • 10. 10SEC-2015 So, if you still don’t
  • 11. 11SEC-2015 Tasks We want our UI to not block. We want our backend to not block. * where it should not block
  • 15. 15SEC-2015 1. Encapsulation principle may be violated 2. Separation of concerns principle may be violated 3. Not easily composable 4. Inversion of control Observer pattern problems
  • 16. 16SEC-2015 $(function() { var currentWord = ''; $('#textin').keypress(function(event) { var key = String.fromCharCode(event.keyCode || event.charCode); if (!key.match(/[w]/) && currentWord) { var link = 'https://twitter.com/hashtag/' + currentWord; $('#textout').append($(' ')).append( $('<a/>').attr('href', link).text('#' + currentWord) ); currentWord = ''; } else if (key) { currentWord += key; } }); }); Example: Hash tagger State Mixing logic with presentation No easy way to compose with another handler of keypress
  • 17. 17SEC-2015 Callback hell public class ReportsEntryPoint { @Override public void onModuleLoad() { String documentIdString = Window.Location.getParameter("docId"); if (documentIdString != null && !documentIdString.isEmpty()) { try { final Long documentId = Long.parseLong(documentIdString); MainService.Util.getInstance().findReport(documentId, new AsyncCallback<ReportDto>() { // Getting Report information first @Override public void onSuccess(ReportDto result) { final ReportDto processedReport = result; MainService.Util.getInstance().getUserInfo(processedReport.getUserId(), processedReport.getCompanyId(), new AsyncCallback<UserCompanyDto>() { // Getting user information for future form initialization @Override public void onSuccess(UserCompanyDto result) { UserDataHolder.getInstance().setUserCompanyDto(result); MainService.Util.getInstance().getDProfile(processedReport.getCompanyId(), new AsyncCallback<DProfileDto>() { // Getting company profile for future form initialization @Override public void onSuccess(DProfileDto result) { UserDataHolder.getInstance().setDProfileDto(result); MainService.Util.getInstance().getPProfile(processedReport.getCompanyId(), new AsyncCallback<PProfileDto>() { // Getting company profile for future form initialization @Override public void onSuccess(PProfileDto result) { UserDataHolder.getInstance().setPProfileDto(result); MainService.Util.getInstance().getFormDto(processedReport, new AsyncCallback<FormDTO>() { // Getting report document form @Override public void onFailure(Throwable caught) { Window.alert("Can't get document: " + caught.getMessage()); ReportEditorEntryPoint.windowClose(); } @Override public void onSuccess(FormDTO result) { if (result == null) { Window.alert("Can't get document."); ReportEditorEntryPoint.windowClose(); return; } // -- some code to process if finally everything is ok! } }) http://callbackhell.com
  • 18. 18SEC-2015 Goods // handling single value Optional<Double> amount = Optional.of(1.0); int roundedAmount = amount.orElse(2.0).intValue(); // handling multiple values Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) .filter(i -> i % 2 == 0).skip(1).limit(2).forEachOrdered(System.out::println);
  • 19. 19SEC-2015 List<String> yellowFruits = new LinkedList<>(); for (String fruit : fruits) { if (fruit.toLowerCase().contains("yellow")) { yellowFruits.add(fruit); } } Collections.sort(yellowFruits); for (String fruit : yellowFruits) { System.out.println(fruit); } fruits.stream() .filter(f -> f.toLowerCase().contains("yellow")) .sorted() .forEach(System.out::println);
  • 22. 22SEC-2015 Definition Reactive programming is paradigm oriented around data flows and propagation of change. http://en.wikipedia.org/wiki/Reactive_programming
  • 23. 23SEC-2015 Reactive programming approach Provide handy abstractions: • Events and Event streams • Behaviors
  • 24. 24SEC-2015 Event stream transformation ‘E’ pressed ‘p’ pressed ‘a’ pressed ‘m’ pressed 69 112 97 109 map() •e -> e.charCode
  • 25. 25SEC-2015 combine() – stream containing events from either combined streams concat() – stream containing items of first stream and then of another stream Stream transformation map(Type1 => Type2) – stream of values from given function applied to each element in source stream filter(Type => Boolean) – stream of values from source stream for which given function returns True reduce((Type1, Type2) => Type1) (or scan(Fn, seed)) – stream of single value which is result of applying given function to element in source stream and result of previous call to given function skip(num) – stream produced from source stream by skipping num elements take(num) – stream produced from source stream by taking num first elements Transforming Combining
  • 26. 26SEC-2015 Example: Hash tagger reactive No global state Clear separation of concerns Declarative description $(function () { var keyStream = Rx.Observable.fromEvent($('#textin'), 'keypress') .map(function (event) { return String.fromCharCode(event.keyCode || event.charCode); }); var endOfWordStream = keyStream.filter(function (char) { return !String(char).match(/[w]/); }); var wordStream = keyStream.buffer(endOfWordStream); var uiUpdater = Rx.Observer.create(function (word) { word = word.join('').trim(); var link = 'https://twitter.com/hashtag/' + word; $('#textout').append($(' ')).append( $('<a/>').attr('href', link).text('#' + word) ); }); wordStream.subscribe(uiUpdater); }); Composable API
  • 27. 27SEC-2015 Behavior (Signal) Behaviors are used to express continuous dependency between values. They are often referred to as function from time domain to value domain. They are also called signals or properties. Example: 𝛼 = 90 - minute x 6 angle of minute arrow on the clock
  • 30. 30SEC-2015 Example: Arkanoid – using property for mouse control // some constants var canvasLeft = $('#gamecanvas').offset().left + window.screenX; var canvasRight = canvasLeft + $('#gamecanvas').width(); var canvasMid = (canvasRight + canvasLeft) / 2; // define event stream for mouse movement var mousePos = $('html') .asEventStream('mousemove') .map(function (event) { return {x: event.screenX, y: event.screenY}; }); // define paddle position as a property in terms of mouse – stateless computation var vausPos = mousePos.map(function (canvasLeft, canvasMid, canvasRight, coords) { return ((coords.x < canvasLeft || coords.x > (canvasRight - 40)) ? (coords.x < canvasMid ? canvasLeft : (canvasRight - 40)) : coords.x) - canvasLeft; }, canvasLeft, canvasMid, canvasRight).toProperty(); // tie property to presentation vausPos.assign($('#vaus'), 'css', 'left');
  • 31. 31SEC-2015 Futures and promises Promise Future Deferred PromiseJavaScript Scala CompletableFutureJava 8 Single write Multiple read
  • 32. 32SEC-2015 Producer Consumer import scala.concurrent.{ future, promise } import scala.concurrent.ExecutionContext.Implicits.global val p = promise[T] val f = p.future val producer = future { // async val r = produceSomething() p success r // completion of future scontinueDoingSomethingUnrelated() } val consumer = future { // async startDoingSomething() f onSuccess { // what to do on completion case r => doSomethingWithResult() } }
  • 33. 33SEC-2015 Single item Many items Pull/ Synchronous Optional Iterator/ Iterable Push/ Asynchronous Future Observer/ Observable
  • 34. 34SEC-2015 Reactive programming Benefits • gives you a base for creating reactive systems • gives you means of handling async in more elegant way • stimulates you to write more concise code Drawbacks • might be harder do debug
  • 36. 36SEC-2015 Think about how data should flow instead of what you do to make it flow
  • 37. 37SEC-2015 Designing your API consider making it asynchronous
  • 39. 39SEC-2015 • Rx JS (http://reactivex.io/) – Observable on steroids • Bacon.js (https://baconjs.github.io/) – EventStreams and Properties (behaviors) • Kefir.js (https://rpominov.github.io/kefir/) - inspired by Bacon.js and RxJS with focus on high performance and low memory usage Tools - Frontend
  • 40. 40SEC-2015 • Java 8 (hello to Streams, lambdas, CompletableFuture) • Scala (gives a good taste of functional paradigm while letting you have old habits) • RxJava (https://github.com/ReactiveX/RxJava/) Tools - Backend
  • 41. 41SEC-2015 References • http://en.wikipedia.org/wiki/Reactive_programming • http://en.wikipedia.org/wiki/Dataflow_programming • http://www.reactivemanifesto.org/ • https://github.com/Reactive-Extensions/RxJS • https://baconjs.github.io/ • What does it mean to be reactive by Erik Meijer https://www.youtube.com/watch?v=sTSQlYX5DU0 • http://www.infoq.com/presentations/Netflix-API-rxjava- hystrix/ • https://gist.github.com/staltz/868e7e9bc2a7b8c1f754

Hinweis der Redaktion

  1. Hello to everybody. First of all, I am very excited to have an opportunity to speak to you today. My speech is about some of the useful programming patterns collectively called ‘reactive programming’.
  2. Today I will try to explain what do these buzz words mean, why would anyone bother and how reactive programming principles can be applied on practice in day-to-day work. There is more than one way to be reactive with no chance to cover them all in half an hour speech so we will particularly look on functional reactive programming and advantages it can bring to you.
  3. So. Why do we have this whole conference devoted to digital engagement? If we go sites like internetworldstats.com we could find some interesting figures. For the last decade amount of Internet users has grown in more than 3 times. Now, the latest statistics from Facebook states 1,4 billion monthly active users. And that is just for single application! It appears that last decade changed significantly the role and availability of digital services in our lives. We check-in, share and consume opinions, authorize with Facebook/twitter in lots of places. Permanent presence with smartphones and other personal devices is perceived now as quite natural.
  4. If you pressed a button and saw a glitch before an intended action happened you start thinking the app is not good enough. It is not interesting for you to know that datacenter experiences blackout and that is why you can’t access something. It’s quite good to have all the documents required with you or read news while you’re on the way to your job. Applications stop to be local to your computer – you expect integration and availability
  5. With internet and devices becoming ubiquitous our expectations from the services being used are changed, so as the engineering challenges being faced. From tens of servers, seconds of response, gigabytes to internet of things, 100% uptime, miliseconds response 2003 – Android 2004 – Facebook 2006 – AWS, twitter 2007 – iPhone 2010 – Instagram, Azure 2011 – Google+
  6. These expectations led engineers to solve similar problems. If we generalize, they all come to following set of properties that system architecture should have to be able to react to different stimulus: events, load, failures and of course user. That is summarized in Reactive manifesto.
  7. Message or event driven nature enables loose coupling between components that is a good thing for quickly replacing failed component. This aspect also contributes to system flexibility as it enables location transparency and thus horizontal scaling. Careful encapsulation of the state or even lack of it within the system allows vertical scalability (usage of multiple cores). Provided system is elastic and resilient it can still provide acceptable responsiveness to user interaction and that is the key of user experience.
  8. Let’s look at the problem that reactive systems try to solve. Our frontend is usually single threaded thus blocking on anything there is equivalent to death.
  9. For web-application we may want to move from multiple small requests towards single big request. Achieving that requires efficient concurrency handling on backend because otherwise single fat request processing can be slower than multiple light ones even despite saved network latency.
  10. We want to model the real world where actions are driven by certain events – e.g. toggling the switch, moving mouse, change in the temperature. Common about these events are that they appear at some moment and we don’t know in advance when they do. That is usual thing to deal with for every programmer, I guess. What do we usually do to handle events?
  11. The answer is plain old Observer pattern. We register a callback to be executed when event of interest occurs and it gets executed by call to notify(). So far so good – we seem to start being reactive doing some stuff whenever something happens. But is this all that we need?
  12. It’s really simple and well understandable but can cause us troubles: - To make certain state available in multiple related observers we tend to move it to broader scope that it should be. - Usually, we put everything needed to process event within callback and these actions may be quite of different nature, e.g. calculations and UI updates. It might be not good to mix. - When you need to consider in your reaction several events simultaneously you start making spaghetti. - You place the code important to understand how your app functions within callback handlers – the flow is inverted thus harder to understand.
  13. Let’s take a look on example. Hash tagger listens text area for key presses, accumulates them and then adds new hashtag to output area once word is ready. This implementation is obviously quite simple but it demonstrates the issues we highlighted: state is more global then it should, logic holds changing presentation, no easy way to combine one callback with another.
  14. If previous one was not bad enough for you, here is another sample from project I worked on. It has all those issues but multiplied in 10 times and this is from real code of GWT-based application dealing with async javascript UI for reports display. You may not try to read code, it does not really matter – I tried hard to fit it into the slide so removed failures handling as well as business logic. You can think that something is bad with your code if it has characteristic shape. This code seems to contain many boilerplate present there just to support how we express the idea in programming language. Can we do better?
  15. If we look around we may notice that we already have some nice stuff. If you are Java developer like me you most probably enjoy enhancements that Java 8 brought with Streams, Optionals and Lambdas. Making at least some boilerplate implicit gives us more space to think what we want to say rather than how we want to say with more concise code.
  16. If we look around we may notice that we already have some nice stuff. If you are Java developer like me you most probably enjoy enhancements that Java 8 brought with Streams, Optionals and Lambdas. Making at least some boilerplate implicit gives us more space to think what we want to say rather than how we want to say with more concise code.
  17. But these constructs are using pull synchronous model and not capable dealing with asynchronous data.
  18. It’s now right time to come to the next questions – What is reactive programming?
  19. If we dig into history we can find that definition of reactive programming is quite similar to the one of dataflow programming first invented at late 60s. Traditional control flow or imperative programming is focused on sequence of instructions that might potentially modify data. Data flow instead is focused on data movement and models the program as graph with explicit connections between data processing functions that are triggered whenever the inputs are available.
  20. Reactive programming uses two main abstractions to model dataflow: Discrete one with events and their streams. Probably, the most common dataflow model is stream. Anything can really be defined as such stream - mouse moves, mouse clicks, key presses, etc. 2. Continuous one with functions that represent value-time dependency. Such functions are called behaviours or signals
  21. Having one stream we can use it to define other streams. We do it by defining different combinators on top of the stream. Combinator takes some code (function) that transforms underlying stream into new one. Ability to pass functions as parameters as well as return them and overall treating them as first class members is characteristic of functional programming paradigm. So here is where functional programming comes in shiny and this is why whenever talking about reactive programming you most probably will hear functional reactive programming or FRP. The key idea here is that we don’t work with values in regular way but obtain new stream by applying transformation function to it.
  22. There is a handful of most common transformer functions. Using these allows to hide explicit state manipulation and stimulates
  23. In this example we don’t have currentWord accumulator as global state – it is hidden.
  24. Usual semantics with imperative approach is calculate the statement value once it encountered. But in reactive paradigm this is dependency established once and updated going forwards whenever member values change so angle changes with minute of an hour without need from you to do something about this. Another often mentioned example is cell formulas in MS Excel.
  25. Signal changes can emit events and events can produce signals – it easy to convert between each other.
  26. The game is about using ‘Vaus’ spaceship to kick the ball and break the bricks
  27. First – we define some constants for convenience of coordinate calculations. Second – we define what should our paddle position depend on – mouse. Third – we define property that expresses actual dependency between mouse position and vaus position. Finally, we just tie this property to presentation once.
  28. You don’t always deal with sequences but still want all that good when working simple value? Here is where another useful abstraction for handling async results without blocking fits - Futures. There are slight difference in terminology but essentially these are the same. The idea is to decouple producer and consumer of asynchronous operation in composable way.
  29. Summarizing the concepts which we just walked through we can see that they cover all the cases we usually have within software systems which have very similar interfaces and are composable. Talking about async part – we get the means of work with values that we will get in future as if they were present and means for expressing processing (potentially infinite) stream of items that might appear sometime like if they were available.
  30. That is what reactive programming gives to you: it makes implicit a significant amount of computation that must be expressed explicitly in other programming paradigms. It’s all about asynchronous computations and means to conveniently deal with it.
  31. In this way you put good foundation into your API and encourage users to become closer to reactive but still give an option to remain synchronous.
  32. From my personal experience I can say that it greatly widens your outlook. Sometime it may be mind blowing. But definitely it will make your code better. That is the edge between using the stuff I’ve been talking about and understanding the roots behind as a whole picture. You may want to review how you usually deal with the state. We may not be ready to completely refuse mutable state and become functional purists but it is worth looking into functional techniques of its implicit management – this can save us hade-ache especially with distributed multithreaded systems.