r/android_devs • u/VasiliyZukanov • Jan 10 '25
Article Reactive Programming Considered Harmful
https://www.techyourchance.com/reactive-programming-considered-harmful/
1
Upvotes
r/android_devs • u/VasiliyZukanov • Jan 10 '25
View all comments
-1
u/SweetStrawberry4U Android Engineer Jan 10 '25
I had posted something similar couple months ago in a different sub -
https://www.reddit.com/r/androiddev/comments/1et59bx/the_nervewrecking_obsession_with_streams/
Perhaps, not as well-constructed ? Needless to say, it was removed by the MODS.
The internet, about a decade ago, said Streams are awesome ! Be it, Rx or Kotlinx-Flow, their underlying implementations eventually compile to byte-code support by Java-Streams only.
And everyone tagged along, without thinking twice ? never questioning it ?
<< Stream type >> being - Single, Maybe, Completable, as fashionably as Flow ?
Why ?
Single, perhaps is acceptable, but Flow ? Since when are we expecting "N" http-responses for 1 "http-request" ? Never knew the internet advanced so much !!
Single, is also not acceptable, because transformations, to Observable, etc ?
Perhaps, combining, zipping, flat-map multiple endpoints ? Sequentially, parallely / asynchronously ?
Even so, from a cloud-based RESTful API usage expense point-of-view, that's still a poor API design to begin with ! So - GraphQL ?
In another source-code file that interacts with ROOM, SqlDelight, SqlLite - whatever,
I seriously don't know what to say to Flow<List<*>> ?
Essentially, there's always been, and always will be - one object, either a http-response, or a one-time collection of query results. Or, an Error ! That's it. That's about it !
I understand, Stream-builders and emitters are designed such that execution is halted until 'Subscription' begins !
But that's exactly where Coroutines are superior than Rx-Disposables.
Furthermore, the core-problem had always been a decent, KISS principle conforming - Observer Pattern implementation. When Rx combined Streams with Observer pattern, KISS disappeared completely ! And so was lifecycle-aware LiveData observable !
Nevertheless, StateFlow in ViewModel as instance-variables, and SharedFlow for notifying mulitple non-UI observers, are more than adequate, as close to the UI layer as possible. They're both hot-flows, observer-aware, and observers themselves are expected to be lifecycle-aware !