I wanna start to learn Rx reactive programming I k...
# android
a
I wanna start to learn Rx reactive programming I know some concepts but didn't use it before 1- Could u please someone recommend me something to learn? 2- someone told me that I have to learn it in java first, is it true? 3- also in kotlin i see rxkotlin, coroutines, rxAndroid, I don't know what is preferred? thanks in advance β™₯️
k
you are welcomed to join in #rx channel to ask any question you have. Rxjava is the base library what we use. RxKotlin and RxAndroid is just an extension on top of RxJava.
πŸ‘Œ 1
d
- 1 - Android specifically or just JVM in general? - 2 - Nope! Absolutely not. - 3 - Coroutines!!!
πŸ‘ 1
k
Coroutine
is not reactive programming
d
What about Channels, Flows and such?
Flow is great, don’t get me wrong it is not yet stable and I am not sure what is the interoperability with java.
d
No real java interop. Sure it's not stable but it's still the "Kotlin way" of doing things.
k
I would recommend also to read this book https://g.co/kgs/eta2pp Helped me a lot
a
I don't like self marketing but this is just too perfect. I recently released a book through the RayWenderlich website (which is a dope website if you're looking for a source of tutorials) about learning RxJava from start to finish. The RW style is to have each chapter resemble a tutorial that slowly builds more and more complex stuff as you go
β™₯️ 1
πŸ‘Œ 1
For number 3, it depends what you're trying to do. If all you're trying to do is make a network call and show a list of items, I'd strongly consider spending some time learning about coroutines. If you're actually interested in more complex use cases or reactive programming in general RxJava is super well supported by the community, or if you're feeling adventurous you could check out Flow
☝️ 1
πŸ‘Œ 1
A lot of people in the Android ecosystem have been using RxJava as a simple threading solution - those people will (correctly) tell you to use coroutines instead of RxJava. However, if you're actually looking for reactive programming or stream based programming it's not the correct comparison.
πŸ‘† 1
πŸ‘Œ 1
πŸ‘ 1
k
yeah, that is also true! Raywenderlich is a great source to learn, check it out you won’t be disappointed. πŸ™‚ πŸ‘ for that
πŸ‘ 1
g
I would like to add tho Flow is not directly implementing Reactive Streams specification, but it for sure implementation of reactive programming paradigm and honestly I don't think that to be reactive library you should be directly compatible with specification (especially if you provide adapter for this, as Flow does), for example Observable from RxJava is not compatible directly, only Flowable
πŸ‘Œ 1
πŸ‘ 1
2. Up to you, you can use Java or Kotlin, no big difference honestly 3. Doesn't make a lot of sense in general. Because you mentioned completely not compatible libraries: RxKotlin - is just wrapper with bunch of Kotlin extensions for RxJava to make it more pleasant to use RxAndroid - is just a library that provides Android Main thread scheduler for RxJava (and allow to use any handler for this) So real choice is: RxJava or kotlinx.coroutines Flow and Channels (other parts just not reactive) And If you really want to know/learn reactive programming start from RxJava
πŸ‘ 1
πŸ‘Œ 1
a
@kioba thanks a lot
πŸ‘ 1
@Dominaezzz thanks for reply yeah 1- Android specifically, and I prefer kotlin
@alexsullivan114 thanks a lot, man, I wanna learn about Rx just to know about it, I don't have a case to solve, just for level up my experiance but i prefer kotlin cuz i use it more than java these days. I have a silly question πŸ˜„ Can I use rxjava in android/kotlin project ? thanks
g
Sure, RxJava is completely fine for Kotlin and Android, just also use RxKotlin to handle some SAM issues of Java interop and use RxAndroid to have Scheduler for Android main thread
β™₯️ 1
πŸ‘Œ 1
πŸ™ 1
a
@am414 That's not a silly quesiton at all. There's a lot of confusing names being thrown around here. The short answer is absolutely. The above book is 100% in Kotlin and it's all abou tusing Rx**Java**. The longer answer is that the interop between Kotlin and Java is so good that there's no real need to rewrite Java libraries in Kotlin - RxJava is a big library, so rewriting it would be a huge endeavor and not worth the effort. To further complicate things, there is a RxKotlin library. But it actually just provides a few convenient Kotlin wrapper methods for RxJava - it's not at all a total rewrite of RxJava! RxKotlin is a very slim library whose sole purpose is to add a few nice Kotlin extensions/wrapper functions to the RxJava library. To add another layer of nonsense, there's also a RxAndroid library! And it is the simplest of all - it really only offers a
Scheduler
(which is an RxJava concept) that interacts with Androids main thread. The naming of these three libraries is super duper confusing. To sum it up - they all revolve around RxJava. RxKotlin provides a few nice extensions/wrappers to RxJava. RxAndroid provides access tot he Android main thread.
β™₯️ 1
πŸ™ 1
πŸ‘Œ 1
a
@gildor thanks a lot for ur help, i really appreciate ur help have a nice day β™₯️
πŸ‘ 1
@alexsullivan114 thanks a lot for ur time and the long answer, I was thought that rxjava is just for java so maybe rxkotlin for kotlin πŸ˜‚ I really appreciate ur help have a nice day β™₯️
a
No problem, let me know if you have any other questions
β™₯️ 1