frp (rx way) · create car example: frp. 15 15 agenda motivation functional reactive programming...

Post on 27-Jun-2020

4 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

1

FRP (Rx way)

MARCH 2017

2

2

AGENDA MOTIVATION FUNCTIONAL REACTIVE PROGRAMMING

INTRO DEMO

3

3

MOORE’S LAW

Simplified version

Processor speeds, or overall processing power for computers will double every two years.

You could count on hardware improvements and wait for your app’s performance to increase

Real version

The number of transistors on an affordable CPU would double every two years

44

4

WHAT HAPPENED WITH THOSE EXTRA TRANSISTORS?

5

5

PARALLEL PROGRAMMING

Parallel programming is the only way to use hardware improvement to increase performance in the future!

6

6

CONCURRENT PROGRAMMING

• Internet:• December 2000 … 361 millions of users … 5.8% of world population

• September 2016 .... 3675 millions of users … 50.1% of world population

• Web programming

• Communication with external devices• Sensors• Bluetooth• …

77

7

MULTITHREADING IS UNAVOIDABLE

8

8

SHARED MUTABLE STATES

• Some states are “invalid” and can crash or block app

• Multiple points of access => hard to control states

PROBLEM:

• Access control - setters/getters (OOP)

PREVENTION:

9

9

SHARED MUTABLE STATES + MULTITHREADING

Without multithreading, bugs are 100% reproducible.• all conditions are under our control => we control execution order

With multithreading, bugs are intermittent (<< 100%)• some conditions are out of our control => execution order is unpredictable

NONDETERMINISTIC BEHAVIOUR => PROGRAMMING HELL

10

10

SOLUTIONS ?

• Remove Shared Mutable States completely (???) • Functional programming

• Remove Shared Mutable States as much as possible• Remove unnecessary states

• Make const everything that can be const

• Use some Functional programming techniques (work with collections, higher order functions)

11

11

CAR ASSEMBLY

1212

12

CREATE CAR EXAMPLE: SINGLE-THREADED

1313

13

CREATE CAR EXAMPLE: MULTI-THREADED

1414

14

CREATE CAR EXAMPLE: FRP

15

15

AGENDA MOTIVATION FUNCTIONAL REACTIVE PROGRAMMING

INTRO DEMO

1616

16

MEET THE OBSERVABLE

1717

17

MEET THE OBSERVABLE

Observable is the object that represent the stream of data

Observer can subscribe to an Observable

Operator is basically a function that accept Observable as operand, instead of the data.

Observable can send three types of signals: Value signal

Completed signal

Error signal

18

18

OBSERVABLE VS ITERABLE

Iterable:

A container object capable of returning its members one at a time.

It is possible to implement all functional operators for work with enumerable collections to work with observables ! (i.e. map, zip, filter ...)

For example:

someIterable.map(someFunction) -> newIterable

someObservable.map(someFunction) -> newObservable

1919

19

OBSERVABLE VS ITERABLE

• At one point of time ALL of the Iterable elements are accessible

• Only one element of the Observable is accessible at the moment of its creation

• Iterable have a pull based access

• Observable have a push based access

• It is possible to convert from Observable to Iterable and vice versa

2020

20

MAP OPERATOR

21

21

CALLBACK VS OBSERVABLE (BRIDGING)

void myAsyncFunction(Data someData, Callback<MyType> myCallback);

Observable<MyType> myFrpAsyncFunction(Data someData);

22

22

AGENDA MOTIVATION FUNCTIONAL REACTIVE PROGRAMMING

INTRO DEMO

23

23

DEMO: DOWNLOAD IMAGE

24

24

IMPERATIVE VS. DECLARATIVE

25

25

IMPERATIVE VS. DECLARATIVE

26

26

DEMO: RGB SLIDERS (PART 1)

27

27

DEMO: RGB SLIDERS (PART 2)

28

28

DEMO: RGB SLIDERS (PART 3)

29

29

EXTERNAL LINKS

http://reactivex.io/

http://rxmarbles.com/

30

SLOBODAN PAVICANDROID DEVELOPER

RASKO GOJKOVICSENIOR IOS DEVELOPER

top related