U
U
uvelichitel2016-02-09 02:09:18
Programming
uvelichitel, 2016-02-09 02:09:18

What problems does reactive programming solve?

I'm trying to get my head around what reactive programming is all about. wikipedia says - in general, the propagation of changes, as in the formulas of excel tables. From a ReactJS perspective, ReduxJS is data streams. The original microsoft articles talk about behaviors, events and their composition, which is enough. The reactive manifesto mentions responsiveness, fault tolerance, and resilience to loads. I don't get a clear picture.
Can you please tell me the classic problems of reactive programming, for which it was created?
I hope in this way to comprehend what it is all the same.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Larry Underwood, 2016-02-09
@uvelichitel

I hope I understood your question correctly.
I store photos from Mars in HD format in the database, I make a request for 100 photos, the task is to show 100 photos sequentially on the screen.
Standard approach: I make a request to the database for 100 photos, wait 2 seconds, get an array of 100 photos,
run through the collection with an iterator and show the pictures on the screen
pseudocode:

pics = GetPicsFromDatabase();
foreach(var pic in pics)
  ShowPic(pic)

Reactive approach: I make a request to the database for 100 photos and set the request handler to a callback that processes the next element of the collection
pseudocode:
// somecode
GetPicsFromDatabaseReactive(NextPictureHandler);
// somecode
NextPictureHandler(Image pic)
{
  ShowPic(pic)
}

In the first case, we ourselves explicitly pulled out the next element of the list (pull), and in the second case, the data source itself threw the next element to us when it was ready (push).
In the first case, we wait until the data source is formed (usually we occupy a thread) and after that we manually view the result, in the second case, the data source will notify us when it is ready.
What does this give us?
Asynchrony - in UI, for example, this gives responsiveness)
Scalability - the data source (a collection of pictures) and the receiver (our pseudocode that shows pictures) are not connected, the lack of connection gives us the opportunity to connect at least 10 image processors (an example one in black and white outputs, the other sepia imposes, etc.)
Fault tolerance is achieved by the fact that if the first handler dies, for example, an exception takes off in its thread, which knocks down the thread (I apologize for the rough example), then the action will be performed by the backup handler (we can hang at least 10 of them, right?)

N
nasnetstep, 2016-05-20
@nasnetstep

Wikipedia example
In imperative programming, expression
means to take the current values ​​of 'b' and 'c', add them up and assign 'a' the result. Further changes to the parameters 'b' and 'c' do not affect 'a'.
In reactive programming, the same expression:
Means that 'a' is the sum of 'b' and 'c'. If 'b' or 'c' changes in the future, this will affect the value of 'a'.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question