Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reason for using reactive programming in simple cases

Please, can somebody explain me what are the advantages of using reactive style:

Observable<String> greeting = Observable.just("Hello");
Observable<String> yelling = greeting.map(s -> s.toUppercase());

instead of simple imperative style:

String greeting = "Hello";
String yelling = greeting.toUppercase();

I understand reactive programming like the same “API” for database access, UI, computation, network access and etc. But why we need to use reactive programming for simple toUppercase

like image 941
Sever Avatar asked Nov 11 '17 17:11

Sever


1 Answers

Apart of all no blocking features, another great feature to use Reactive programing, is the important use of backpressure. Normally is used in situations where your publisher emit more information than your consumer can process.

So having this mechanism you can control the flow of traffic between both and avoid the nasty out of memory problems.

You can see some practicle examples of Reactive programing here https://github.com/politrons/reactive

And about back pressure here https://github.com/politrons/Akka/blob/master/src/main/scala/stream/BackPressure.scala

By the way, the only disadvantage about reactive programing, is the curve of learning because you´re changing paradigm of programing. But nowadays all important companies respect and follow the reactive manifesto http://www.reactivemanifesto.org/

If you want to see some practical examples you can reference here https://github.com/politrons/reactive

like image 51
paul Avatar answered Sep 28 '22 06:09

paul