T
T
turbolizard2021-03-24 17:43:11
Java
turbolizard, 2021-03-24 17:43:11

RxJava in 2021. Is it necessary?

From time to time I do development for Android (as a hobby), I study all sorts of innovations, and so on, but that in 2017 I didn’t understand why RxJava was needed, I still can’t understand now. After all, all he offers is streams with subscribers who work in another thread and die after `onComplete` (or am I not understanding correctly?). The year is 2021, coroutines for the background, is it important to continue to understand RxJava?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-03-24
@zagayevskiy

RxJava and coroutines are a little bit different. Rx is about stateless and representing everything as streams of immutable states (data). Coroutines are about stateful and about managing many asynchronous entities.
It so happened that in our multi-threaded world there is concurrency in both approaches. But this does not mean that it is necessary to take and oppose Rx to coroutines.
The request for Rx is so large that flow was brought to kotlinx - this is the same reactive approach, only based on coroutines. What they fought against, what Elizarov preached against, they ran into it, and they also spawned new operators who also need to be known. And they made it extremely difficult.

flowOf(123)
   .map(::calculateSomething)
   .filter(::myFilter)
   .collect(::collectIt)

How many Asynchronous requests are there in this code? Where can it sleep forever? Unknown... the framework makes it easy to write code in such a way that everything explodes without you even noticing.
Is it good that using coroutines you can write asynchronous code that looks identical to synchronous? My opinion - no, not good, because keeping two paradigms about one code in mind is difficult. And if someone used coroutines with multithreading under iOS (Kotlin / Native), there you need to keep in mind three paradigms about the same code. This is bad.
A lot of code is written on Rx, many people find it difficult to live without it. Many tasks on Rx are solved so much easier that you really think that you can't do without it.
If you need coroutines or Rx to go to the network on the background, and then show the data in the UI, you don’t really need either coroutines or Rx.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question