SlideShare a Scribd company logo
promhx
Programming Reactive Object Methods in Haxe
A bit about me…
Data Visualization + Data
Science + Machine Learning +
Advanced UI
I “Promhx” to explain…
var p = new Promise<Explanation>();
var s = new Stream<Examples>();
var d = new Deferred<Understanding>();
But first some background…
Asynchronous Programming
• Client code is often single threaded. Excessive time delays due to computation
causes rendering lag, and can block IO.

We often need to break up computation in multiple loops.
• Client code often handles server responses through asynchronous callbacks. 

We need to wait for the server to respond.
• Managing error handling often involves careful use of try-catch in several
locations. It is difficult to ensure all exceptions are caught.

We want a better way of handling generic errors.
• Callbacks generally follow a nested pattern

Nested code indentation patterns can become difficult to read.
• Server side platforms are finding success with asynchronous programming
techniques, with the same opportunities and pitfalls (nodejs). However, server side
implementations often have different methods of managing asynchronous
callbacks.

We want to implement asynchronous code the same way on client/server.
Asynchronous Programming
How many potential problems in this code?
Asynchronous Programming
Missed error handling
Lost space due to indentation
Duplicate error handling
Not *really* 0 seconds
Functional Reactive
Programming to the Rescue
Wikipedia : “In computing, reactive programming is a programming
paradigm oriented around data flows and the propagation of change.
This means that it should be possible to express static or dynamic data
flows with ease in the programming languages used, and that the
underlying execution model will automatically propagate changes
through the data flow.”
Reactive programming moves the unit of asynchronous programming
from a callback to a special object. It is a variable over time.
Promhx Object
Container Object
Value : _
Promhx Object
Container Object
Value :_resolve thenx function(_){…}
function(_){…}
function(_){…}
Promhx Object
Container Object
Value : xresolve thenx function(x){…}
function(x){…}
function(x){…}
Promhx Object
Container Object
Value : xresolve thenx function(x){…}
function(x){…}
function(x){…}
Loop n Loop n+1
Promhx Looping
Container Object
Value : x
Loop n Loop n+1
setImmediate
• Avoid the default delay of
4ms-10ms in setTimeout
• Avoid scheduling a new paint
task in
requestAnimationFrame
• Provide polyfill for backwards
compatibility (via noble.js)
Javascript specific details
Promhx Looping
Container Object
Value : x
Loop n Loop n+1
???
Other platforms : BYOEL
(bring your own event loop)
Promhx Object
Chaining
Value :_resolve then_ Value :_resolve then
Loop n Loop n+1 Loop n+2
Promhx Object
Chaining
Value : xresolve thenx Value :_resolve then
Loop n Loop n+1 Loop n+2
Promhx Object
Chaining
Value : xresolve thenx Value : xresolve then
Loop n Loop n+1 Loop n+2
Promhx Object
Chaining
Value : xresolve thenx Value : xresolve then
Loop n Loop n+1 Loop n+2
x
Wikipedia : “In computer science, future, promise, and
delay refer to constructs used for synchronizing in some
concurrent programming languages. They describe an
object that acts as a proxy for a result that is initially
unknown, usually because the computation of its value is
yet incomplete.”
What is a Promise?
What is a (Reactive) Stream?
Wikipedia : “In computer science, a stream is a
sequence of data elements made available over time. A
stream can be thought of as a conveyor belt that allows
items to be processed one at a time rather than in large
batches.”
Promises vs. Streams
• Promises
• Good for providing initial configuration, and ensuring that an asynchronous workflow
progresses “forward”.
• Can only resolve once!
• Streams
• Good for providing general-purpose reactive programming.
• Resolves more than once.
• Promises and Streams
• Generally, promises can be substituted where streams are expected, but not vice-versa.
• Both provide the same error semantics, and optimized asynchronous event loop
management.
• Both use Deferreds as a writable interface…
What is a Deferred?
Deferreds are a writable interface for reactive objects. Use them to prevent other developers
from mistakenly resolving a Promise or Stream that they should not have access to.*
!
*The notable exception is PublicStream, which is globally write-accessible.
What is a Deferred?
Container Object
Value :_
!
resolve
then
x
function(_){…}
function(_){…}
function(_){…}
Deferred
Basics of Reactive
Programming in Promhx
Move the callback to the proxy object
Basics of working with
Promises
then vs. when : instance vs. static usage
Error handling
• Errors are propagated through the reactive chain
• catchError() functions like a try/catch, preventing updates to other reactive variables.
• Use Haxe’s try/catch semantics to catch typed errors.
Promhx Object
Error Handling
Value :_resolve then Value :_resolve then
Loop n Loop n+1 Loop n+2
catchError
(private error linking method)
Promhx Object
Error Handling
Value :_resolve thenE Value :_resolve then
Loop n Loop n+1 Loop n+2
E
catchError
(private error linking method)
Promhx Object
Error Handling
Value :_resolve thenE Value :_resolve then
Loop n Loop n+1 Loop n+2
E E
catchError
(private error linking method)E
Promhx Object
Error Handling
Value :_resolve thenE Value :_resolve then
Loop n Loop n+1 Loop n+2
(private error linking method)
E
E
E
catchError E
Error handling
• errorThen() allows you to convert an error back into the appropriate
variable type.
• This variable can be propagated as if it were resolved normally.
Promhx Object
Recovering from an error
Value :_resolve then
Loop n+1
errorThen
Value :_resolve then
Loop n Loop n+2
Promhx Object
Value :_resolve then
Loop n+1
E
errorThen
E Value :_resolve then
Loop n Loop n+2
Recovering from an error
Promhx Object
Value :_resolve then
Loop n+1
E
errorThen
E Value :xresolve then
X
Loop n Loop n+2
Recovering from an error
Promhx Object
Value :_resolve then
Loop n+1
E
errorThen
E Value :xresolve then
X
X
Loop n Loop n+2
Recovering from an error
Are promhx objects
Monads?
• Type constructor : Create a monadic type for the underlying type. For example
it defines type Promise<Int> for the underlying type Int. I.e. the class
constructor
• unit function : Wraps a value of underlying type into a monad. For Promise
monad it wraps value 2 of type number into value Promise(2) of type
Promise<Int>. I.e. Promise.promise.
• bind function : Chains operations on monadic values. I.e. the “then” function.
…So yes, but why should we
care?
Three requirements for Monads:
Monads are useful
!
• Allows for new capabilities for a given type, and allows the original functions to use
the new capabilities.
• Captures operations on types, making it easier to build complex compositions that
all behave by the same simple rules.
• Represents side-effecting operations cleanly in languages where this is problematic
Monad Composability
• Do-notation provided courtesy of Monax (Stephane Ledorze)
• The “<=“ operator binds the result returned via then()
• We can drop the chain syntax, and write out promises as if they were a
simple series of expressions.
Composability vs. Standards
• JS: callback usage is predominant, especially in
platforms like node.
• Should we follow standards? Standards are good
right?
Promises A+ Spec
Promise<Promise<T>?
pipe/flatMap
then /map
No composability
Well Tested
~30 f tests
x 7 platforms
(2 have problems)
Promhx Speed
That’s it!
• I talked about why we need better asynchronous programming methods
• I talked about the basics of functional reactive programming
• I talked about the basic types of FRP that promhx supports, Promise,
Stream, and PublicStream. I also talked about what each one is
designed for, and how they use Deferred where appropriate.
• I talked about the way promhx handles errors and loop behavior
• I talked about some cool tricks that promhx can do since it behaves as
a monad
• I talked about how fast and well tested the library is
QUESTIONS
?
We’re Hiring!
• UI Dev Positions - Search and other teams
• Offices in Paris/Grenoble/Seattle/(etc.)
(San Francisco HQ)
• Not much Haxe… yet!

More Related Content

What's hot

C++ Coroutines
C++ CoroutinesC++ Coroutines
C++ Coroutines
Sumant Tambe
 
Jvm profiling under the hood
Jvm profiling under the hoodJvm profiling under the hood
Jvm profiling under the hood
RichardWarburton
 
Collections forceawakens
Collections forceawakensCollections forceawakens
Collections forceawakens
RichardWarburton
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
Hithem Ahmed
 
Performance and predictability
Performance and predictabilityPerformance and predictability
Performance and predictability
RichardWarburton
 
Translating Qt Applications
Translating Qt ApplicationsTranslating Qt Applications
Translating Qt Applications
account inactive
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011
Jimmy Schementi
 
Clojure - A practical LISP for the JVM
Clojure - A practical LISP for the JVMClojure - A practical LISP for the JVM
Clojure - A practical LISP for the JVM
Matthias Nüßler
 
Design patterns with kotlin
Design patterns with kotlinDesign patterns with kotlin
Design patterns with kotlin
Alexey Soshin
 
Blocks & GCD
Blocks & GCDBlocks & GCD
Blocks & GCD
rsebbe
 
Java Concurrency in Practice
Java Concurrency in PracticeJava Concurrency in Practice
Java Concurrency in Practice
Alina Dolgikh
 
12 virtualmachine
12 virtualmachine12 virtualmachine
12 virtualmachine
The World of Smalltalk
 
Ns2
Ns2Ns2
Qt Framework Events Signals Threads
Qt Framework Events Signals ThreadsQt Framework Events Signals Threads
Qt Framework Events Signals Threads
Neera Mital
 
NS-2 Tutorial
NS-2 TutorialNS-2 Tutorial
NS-2 Tutorial
code453
 
Fundamental concurrent programming
Fundamental concurrent programmingFundamental concurrent programming
Fundamental concurrent programming
Dimas Prawira
 
Working with NS2
Working with NS2Working with NS2
Working with NS2
chanchal214
 
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ć
 
nn network
nn networknn network
ZFS Log Spacemap - Flushing Algorithm
ZFS Log Spacemap - Flushing AlgorithmZFS Log Spacemap - Flushing Algorithm
ZFS Log Spacemap - Flushing Algorithm
Serapheim-Nikolaos Dimitropoulos
 

What's hot (20)

C++ Coroutines
C++ CoroutinesC++ Coroutines
C++ Coroutines
 
Jvm profiling under the hood
Jvm profiling under the hoodJvm profiling under the hood
Jvm profiling under the hood
 
Collections forceawakens
Collections forceawakensCollections forceawakens
Collections forceawakens
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
Performance and predictability
Performance and predictabilityPerformance and predictability
Performance and predictability
 
Translating Qt Applications
Translating Qt ApplicationsTranslating Qt Applications
Translating Qt Applications
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011
 
Clojure - A practical LISP for the JVM
Clojure - A practical LISP for the JVMClojure - A practical LISP for the JVM
Clojure - A practical LISP for the JVM
 
Design patterns with kotlin
Design patterns with kotlinDesign patterns with kotlin
Design patterns with kotlin
 
Blocks & GCD
Blocks & GCDBlocks & GCD
Blocks & GCD
 
Java Concurrency in Practice
Java Concurrency in PracticeJava Concurrency in Practice
Java Concurrency in Practice
 
12 virtualmachine
12 virtualmachine12 virtualmachine
12 virtualmachine
 
Ns2
Ns2Ns2
Ns2
 
Qt Framework Events Signals Threads
Qt Framework Events Signals ThreadsQt Framework Events Signals Threads
Qt Framework Events Signals Threads
 
NS-2 Tutorial
NS-2 TutorialNS-2 Tutorial
NS-2 Tutorial
 
Fundamental concurrent programming
Fundamental concurrent programmingFundamental concurrent programming
Fundamental concurrent programming
 
Working with NS2
Working with NS2Working with NS2
Working with NS2
 
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)
 
nn network
nn networknn network
nn network
 
ZFS Log Spacemap - Flushing Algorithm
ZFS Log Spacemap - Flushing AlgorithmZFS Log Spacemap - Flushing Algorithm
ZFS Log Spacemap - Flushing Algorithm
 

Similar to WWX14 speech : Justin Donaldson "Promhx : Cross-platform Promises and Reactive Programming in Haxe"

Solve it Differently with Reactive Programming
Solve it Differently with Reactive ProgrammingSolve it Differently with Reactive Programming
Solve it Differently with Reactive Programming
Supun Dissanayake
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
Peter Lawrey
 
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
jeffz
 
DZone_RC_RxJS
DZone_RC_RxJSDZone_RC_RxJS
DZone_RC_RxJS
Luis Atencio
 
Inventing the future Business Programming Language
Inventing the future  Business Programming LanguageInventing the future  Business Programming Language
Inventing the future Business Programming Language
ESUG
 
Concurrency Constructs Overview
Concurrency Constructs OverviewConcurrency Constructs Overview
Concurrency Constructs Overview
stasimus
 
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency ProgrammingConcurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
Sachintha Gunasena
 
A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.
Jason Hearne-McGuiness
 
Go from a PHP Perspective
Go from a PHP PerspectiveGo from a PHP Perspective
Go from a PHP Perspective
Barry Jones
 
Highly concurrent yet natural programming
Highly concurrent yet natural programmingHighly concurrent yet natural programming
Highly concurrent yet natural programming
Infinit
 
20160609 nike techtalks reactive applications tools of the trade
20160609 nike techtalks reactive applications   tools of the trade20160609 nike techtalks reactive applications   tools of the trade
20160609 nike techtalks reactive applications tools of the trade
shinolajla
 
Introduction to OpenSees by Frank McKenna
Introduction to OpenSees by Frank McKennaIntroduction to OpenSees by Frank McKenna
Introduction to OpenSees by Frank McKenna
openseesdays
 
Async/Await Best Practices
Async/Await Best PracticesAsync/Await Best Practices
Async/Await Best Practices
Particular Software
 
Concur15slides
Concur15slidesConcur15slides
Concur15slides
Andrea Cerone
 
From Hours to Minutes: The Journey of Optimizing Mask-RCNN and BERT Using MXNet
From Hours to Minutes: The Journey of Optimizing Mask-RCNN and BERT Using MXNetFrom Hours to Minutes: The Journey of Optimizing Mask-RCNN and BERT Using MXNet
From Hours to Minutes: The Journey of Optimizing Mask-RCNN and BERT Using MXNet
Eric Haibin Lin
 
Lecture 15 run timeenvironment_2
Lecture 15 run timeenvironment_2Lecture 15 run timeenvironment_2
Lecture 15 run timeenvironment_2
Iffat Anjum
 
C# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programmingC# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programming
Praveen Prajapati
 
CNN for modeling sentence
CNN for modeling sentenceCNN for modeling sentence
CNN for modeling sentence
ANISH BHANUSHALI
 
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems
Go Reactive: Event-Driven, Scalable, Resilient & Responsive SystemsGo Reactive: Event-Driven, Scalable, Resilient & Responsive Systems
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems
Jonas Bonér
 
Seattle Scalability Meetup 6-26-13
Seattle Scalability Meetup 6-26-13Seattle Scalability Meetup 6-26-13
Seattle Scalability Meetup 6-26-13
specialk29
 

Similar to WWX14 speech : Justin Donaldson "Promhx : Cross-platform Promises and Reactive Programming in Haxe" (20)

Solve it Differently with Reactive Programming
Solve it Differently with Reactive ProgrammingSolve it Differently with Reactive Programming
Solve it Differently with Reactive Programming
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
 
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
 
DZone_RC_RxJS
DZone_RC_RxJSDZone_RC_RxJS
DZone_RC_RxJS
 
Inventing the future Business Programming Language
Inventing the future  Business Programming LanguageInventing the future  Business Programming Language
Inventing the future Business Programming Language
 
Concurrency Constructs Overview
Concurrency Constructs OverviewConcurrency Constructs Overview
Concurrency Constructs Overview
 
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency ProgrammingConcurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
 
A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.
 
Go from a PHP Perspective
Go from a PHP PerspectiveGo from a PHP Perspective
Go from a PHP Perspective
 
Highly concurrent yet natural programming
Highly concurrent yet natural programmingHighly concurrent yet natural programming
Highly concurrent yet natural programming
 
20160609 nike techtalks reactive applications tools of the trade
20160609 nike techtalks reactive applications   tools of the trade20160609 nike techtalks reactive applications   tools of the trade
20160609 nike techtalks reactive applications tools of the trade
 
Introduction to OpenSees by Frank McKenna
Introduction to OpenSees by Frank McKennaIntroduction to OpenSees by Frank McKenna
Introduction to OpenSees by Frank McKenna
 
Async/Await Best Practices
Async/Await Best PracticesAsync/Await Best Practices
Async/Await Best Practices
 
Concur15slides
Concur15slidesConcur15slides
Concur15slides
 
From Hours to Minutes: The Journey of Optimizing Mask-RCNN and BERT Using MXNet
From Hours to Minutes: The Journey of Optimizing Mask-RCNN and BERT Using MXNetFrom Hours to Minutes: The Journey of Optimizing Mask-RCNN and BERT Using MXNet
From Hours to Minutes: The Journey of Optimizing Mask-RCNN and BERT Using MXNet
 
Lecture 15 run timeenvironment_2
Lecture 15 run timeenvironment_2Lecture 15 run timeenvironment_2
Lecture 15 run timeenvironment_2
 
C# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programmingC# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programming
 
CNN for modeling sentence
CNN for modeling sentenceCNN for modeling sentence
CNN for modeling sentence
 
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems
Go Reactive: Event-Driven, Scalable, Resilient & Responsive SystemsGo Reactive: Event-Driven, Scalable, Resilient & Responsive Systems
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems
 
Seattle Scalability Meetup 6-26-13
Seattle Scalability Meetup 6-26-13Seattle Scalability Meetup 6-26-13
Seattle Scalability Meetup 6-26-13
 

More from antopensource

Atelier node.js
Atelier node.jsAtelier node.js
Atelier node.js
antopensource
 
Créer son logo vectoriel avec Inkscape
Créer son logo vectoriel avec InkscapeCréer son logo vectoriel avec Inkscape
Créer son logo vectoriel avec Inkscape
antopensource
 
Prise en main rapide et facile de Gimp
Prise en main rapide et facile de GimpPrise en main rapide et facile de Gimp
Prise en main rapide et facile de Gimp
antopensource
 
Low fi prototype par Pol Gaosdoué
Low fi prototype par Pol GaosdouéLow fi prototype par Pol Gaosdoué
Low fi prototype par Pol Gaosdoué
antopensource
 
Atelier brand utility 03.11.2015 Silexl Labs2
Atelier brand utility 03.11.2015  Silexl Labs2Atelier brand utility 03.11.2015  Silexl Labs2
Atelier brand utility 03.11.2015 Silexl Labs2
antopensource
 
Atelier Blender Fev-2016 2/2
Atelier Blender Fev-2016  2/2Atelier Blender Fev-2016  2/2
Atelier Blender Fev-2016 2/2
antopensource
 
Atelier Blender Fev-2016 1/2
Atelier Blender Fev-2016 1/2Atelier Blender Fev-2016 1/2
Atelier Blender Fev-2016 1/2
antopensource
 
Silexlabs atelier couleurs 01
Silexlabs atelier couleurs 01Silexlabs atelier couleurs 01
Silexlabs atelier couleurs 01
antopensource
 
Jive the renovation of Aswing
Jive the renovation of AswingJive the renovation of Aswing
Jive the renovation of Aswing
antopensource
 
WWX2014 speech : Elliott Stoneham "Tardis go"
WWX2014 speech : Elliott Stoneham "Tardis go"WWX2014 speech : Elliott Stoneham "Tardis go"
WWX2014 speech : Elliott Stoneham "Tardis go"
antopensource
 
Wwx2014 - Todd Kulick "Shipping One Million Lines of Haxe to (Over) One Milli...
Wwx2014 - Todd Kulick "Shipping One Million Lines of Haxe to (Over) One Milli...Wwx2014 - Todd Kulick "Shipping One Million Lines of Haxe to (Over) One Milli...
Wwx2014 - Todd Kulick "Shipping One Million Lines of Haxe to (Over) One Milli...
antopensource
 

More from antopensource (11)

Atelier node.js
Atelier node.jsAtelier node.js
Atelier node.js
 
Créer son logo vectoriel avec Inkscape
Créer son logo vectoriel avec InkscapeCréer son logo vectoriel avec Inkscape
Créer son logo vectoriel avec Inkscape
 
Prise en main rapide et facile de Gimp
Prise en main rapide et facile de GimpPrise en main rapide et facile de Gimp
Prise en main rapide et facile de Gimp
 
Low fi prototype par Pol Gaosdoué
Low fi prototype par Pol GaosdouéLow fi prototype par Pol Gaosdoué
Low fi prototype par Pol Gaosdoué
 
Atelier brand utility 03.11.2015 Silexl Labs2
Atelier brand utility 03.11.2015  Silexl Labs2Atelier brand utility 03.11.2015  Silexl Labs2
Atelier brand utility 03.11.2015 Silexl Labs2
 
Atelier Blender Fev-2016 2/2
Atelier Blender Fev-2016  2/2Atelier Blender Fev-2016  2/2
Atelier Blender Fev-2016 2/2
 
Atelier Blender Fev-2016 1/2
Atelier Blender Fev-2016 1/2Atelier Blender Fev-2016 1/2
Atelier Blender Fev-2016 1/2
 
Silexlabs atelier couleurs 01
Silexlabs atelier couleurs 01Silexlabs atelier couleurs 01
Silexlabs atelier couleurs 01
 
Jive the renovation of Aswing
Jive the renovation of AswingJive the renovation of Aswing
Jive the renovation of Aswing
 
WWX2014 speech : Elliott Stoneham "Tardis go"
WWX2014 speech : Elliott Stoneham "Tardis go"WWX2014 speech : Elliott Stoneham "Tardis go"
WWX2014 speech : Elliott Stoneham "Tardis go"
 
Wwx2014 - Todd Kulick "Shipping One Million Lines of Haxe to (Over) One Milli...
Wwx2014 - Todd Kulick "Shipping One Million Lines of Haxe to (Over) One Milli...Wwx2014 - Todd Kulick "Shipping One Million Lines of Haxe to (Over) One Milli...
Wwx2014 - Todd Kulick "Shipping One Million Lines of Haxe to (Over) One Milli...
 

Recently uploaded

UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
safelyiotech
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
TaghreedAltamimi
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 

Recently uploaded (20)

UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 

WWX14 speech : Justin Donaldson "Promhx : Cross-platform Promises and Reactive Programming in Haxe"

  • 2. A bit about me… Data Visualization + Data Science + Machine Learning + Advanced UI
  • 3. I “Promhx” to explain… var p = new Promise<Explanation>(); var s = new Stream<Examples>(); var d = new Deferred<Understanding>(); But first some background…
  • 4. Asynchronous Programming • Client code is often single threaded. Excessive time delays due to computation causes rendering lag, and can block IO.
 We often need to break up computation in multiple loops. • Client code often handles server responses through asynchronous callbacks. 
 We need to wait for the server to respond. • Managing error handling often involves careful use of try-catch in several locations. It is difficult to ensure all exceptions are caught.
 We want a better way of handling generic errors. • Callbacks generally follow a nested pattern
 Nested code indentation patterns can become difficult to read. • Server side platforms are finding success with asynchronous programming techniques, with the same opportunities and pitfalls (nodejs). However, server side implementations often have different methods of managing asynchronous callbacks.
 We want to implement asynchronous code the same way on client/server.
  • 5. Asynchronous Programming How many potential problems in this code?
  • 6. Asynchronous Programming Missed error handling Lost space due to indentation Duplicate error handling Not *really* 0 seconds
  • 7. Functional Reactive Programming to the Rescue Wikipedia : “In computing, reactive programming is a programming paradigm oriented around data flows and the propagation of change. This means that it should be possible to express static or dynamic data flows with ease in the programming languages used, and that the underlying execution model will automatically propagate changes through the data flow.” Reactive programming moves the unit of asynchronous programming from a callback to a special object. It is a variable over time.
  • 9. Promhx Object Container Object Value :_resolve thenx function(_){…} function(_){…} function(_){…}
  • 10. Promhx Object Container Object Value : xresolve thenx function(x){…} function(x){…} function(x){…}
  • 11. Promhx Object Container Object Value : xresolve thenx function(x){…} function(x){…} function(x){…} Loop n Loop n+1
  • 12. Promhx Looping Container Object Value : x Loop n Loop n+1 setImmediate • Avoid the default delay of 4ms-10ms in setTimeout • Avoid scheduling a new paint task in requestAnimationFrame • Provide polyfill for backwards compatibility (via noble.js) Javascript specific details
  • 13. Promhx Looping Container Object Value : x Loop n Loop n+1 ??? Other platforms : BYOEL (bring your own event loop)
  • 14. Promhx Object Chaining Value :_resolve then_ Value :_resolve then Loop n Loop n+1 Loop n+2
  • 15. Promhx Object Chaining Value : xresolve thenx Value :_resolve then Loop n Loop n+1 Loop n+2
  • 16. Promhx Object Chaining Value : xresolve thenx Value : xresolve then Loop n Loop n+1 Loop n+2
  • 17. Promhx Object Chaining Value : xresolve thenx Value : xresolve then Loop n Loop n+1 Loop n+2 x
  • 18. Wikipedia : “In computer science, future, promise, and delay refer to constructs used for synchronizing in some concurrent programming languages. They describe an object that acts as a proxy for a result that is initially unknown, usually because the computation of its value is yet incomplete.” What is a Promise?
  • 19. What is a (Reactive) Stream? Wikipedia : “In computer science, a stream is a sequence of data elements made available over time. A stream can be thought of as a conveyor belt that allows items to be processed one at a time rather than in large batches.”
  • 20. Promises vs. Streams • Promises • Good for providing initial configuration, and ensuring that an asynchronous workflow progresses “forward”. • Can only resolve once! • Streams • Good for providing general-purpose reactive programming. • Resolves more than once. • Promises and Streams • Generally, promises can be substituted where streams are expected, but not vice-versa. • Both provide the same error semantics, and optimized asynchronous event loop management. • Both use Deferreds as a writable interface…
  • 21. What is a Deferred? Deferreds are a writable interface for reactive objects. Use them to prevent other developers from mistakenly resolving a Promise or Stream that they should not have access to.* ! *The notable exception is PublicStream, which is globally write-accessible.
  • 22. What is a Deferred? Container Object Value :_ ! resolve then x function(_){…} function(_){…} function(_){…} Deferred
  • 23. Basics of Reactive Programming in Promhx Move the callback to the proxy object
  • 24. Basics of working with Promises then vs. when : instance vs. static usage
  • 25. Error handling • Errors are propagated through the reactive chain • catchError() functions like a try/catch, preventing updates to other reactive variables. • Use Haxe’s try/catch semantics to catch typed errors.
  • 26. Promhx Object Error Handling Value :_resolve then Value :_resolve then Loop n Loop n+1 Loop n+2 catchError (private error linking method)
  • 27. Promhx Object Error Handling Value :_resolve thenE Value :_resolve then Loop n Loop n+1 Loop n+2 E catchError (private error linking method)
  • 28. Promhx Object Error Handling Value :_resolve thenE Value :_resolve then Loop n Loop n+1 Loop n+2 E E catchError (private error linking method)E
  • 29. Promhx Object Error Handling Value :_resolve thenE Value :_resolve then Loop n Loop n+1 Loop n+2 (private error linking method) E E E catchError E
  • 30. Error handling • errorThen() allows you to convert an error back into the appropriate variable type. • This variable can be propagated as if it were resolved normally.
  • 31. Promhx Object Recovering from an error Value :_resolve then Loop n+1 errorThen Value :_resolve then Loop n Loop n+2
  • 32. Promhx Object Value :_resolve then Loop n+1 E errorThen E Value :_resolve then Loop n Loop n+2 Recovering from an error
  • 33. Promhx Object Value :_resolve then Loop n+1 E errorThen E Value :xresolve then X Loop n Loop n+2 Recovering from an error
  • 34. Promhx Object Value :_resolve then Loop n+1 E errorThen E Value :xresolve then X X Loop n Loop n+2 Recovering from an error
  • 35. Are promhx objects Monads? • Type constructor : Create a monadic type for the underlying type. For example it defines type Promise<Int> for the underlying type Int. I.e. the class constructor • unit function : Wraps a value of underlying type into a monad. For Promise monad it wraps value 2 of type number into value Promise(2) of type Promise<Int>. I.e. Promise.promise. • bind function : Chains operations on monadic values. I.e. the “then” function. …So yes, but why should we care? Three requirements for Monads:
  • 36. Monads are useful ! • Allows for new capabilities for a given type, and allows the original functions to use the new capabilities. • Captures operations on types, making it easier to build complex compositions that all behave by the same simple rules. • Represents side-effecting operations cleanly in languages where this is problematic
  • 37. Monad Composability • Do-notation provided courtesy of Monax (Stephane Ledorze) • The “<=“ operator binds the result returned via then() • We can drop the chain syntax, and write out promises as if they were a simple series of expressions.
  • 38. Composability vs. Standards • JS: callback usage is predominant, especially in platforms like node. • Should we follow standards? Standards are good right?
  • 40. Well Tested ~30 f tests x 7 platforms (2 have problems)
  • 42. That’s it! • I talked about why we need better asynchronous programming methods • I talked about the basics of functional reactive programming • I talked about the basic types of FRP that promhx supports, Promise, Stream, and PublicStream. I also talked about what each one is designed for, and how they use Deferred where appropriate. • I talked about the way promhx handles errors and loop behavior • I talked about some cool tricks that promhx can do since it behaves as a monad • I talked about how fast and well tested the library is
  • 44. We’re Hiring! • UI Dev Positions - Search and other teams • Offices in Paris/Grenoble/Seattle/(etc.) (San Francisco HQ) • Not much Haxe… yet!