Kotlin + Rx2: A reactive and functional approach to mobile application development

That is why we turned to Denis nekdenis Neklyudov (Android GDE) and Stepan stepango Goncharov, Android developers at 90Seconds.com. The interview will touch upon several important topics, from the architecture of a mobile application to the use of Rx libraries in projects. So, let's begin…
Denis Neklyudov
- Good afternoon, Denis! Please tell me what is your focus on in the context of development at the moment?
- Good afternoon! Now, like my partner at Mobius, Stepan Goncharov, I am developing a new mobile client for Singapore-based company 90Seconds.com. What I like most about the current project is that Stepan started writing the application from scratch and was able to build a very interesting architecture. Plus, it uses all the modern, one might even say fashionable approaches, such as using Kotlin as a programming language and a reactive approach to working with data.
- A few years ago in an interviewYou talked about your Google Developer Expert status and what it means to you. One of the key phrases, in my opinion, was: “And also to engage in my favorite hobby: share knowledge with people at conferences, in podcasts and in articles.” Please tell me, have you changed your mind about the need to disseminate information and promote ideas?
- I haven’t changed, and 30 issues of our Android development podcast, excellent confirmation to that. I can share another problem that I encountered in these two years, being in the status of GDE. If you come up with the topic “what's new in new Android”, then there are a lot of people who themselves have read the documentation, all 20 pages that you have so neatly put into one convenient presentation, and go in the middle with the words: “Oh, well, it's me I could read it myself. ” And when you come up with a topic unknown to the majority, you tell it and you see that only a small percentage of the audience at all understands what they are talking about, because they are not completely prepared, and there is no time for introductory material in a half-hour presentation. And it’s not even a fact that people who left your first presentation will not leave the second one as well.
That’s why we decided to record podcasts. It will be interesting to everyone to listen to, because there we discuss problems of all levels, a beginner and a professional in the industry will find something useful for themselves there.
- Keeping abreast of the latest events, changes - is this your credo? Does knowing about upcoming changes in the language affect adherence to a particular coding style or are you a proponent of the latest technology?
- I am a supporter of maintaining balance. I can’t stand the extreme: “we have the latest libraries, which are not even in release yet, approaches that have not been tested by time”. And I also don’t like the total conservatism that people, who have accumulated over a dozen cones over many years of experience, try to try new things. You need to try to balance between the development speed that the business needs today and the ability to scale, expand and maintain with the other teams the application that the business will need tomorrow.
- All attention is now focused on Android Nougat, right? What kind of innovations were positively accepted by the developers, I think that during this period from the moment you released you already made up your mind.
- In fact, that Nougat, that Marshmallow, that the other day announced Android O Developer Preview are an organic development of Android Lollipop, without trying to fundamentally change something in the SDK. On the one hand, this is good: in order to support the new version of the OS in the application, it does not take much work. But on the other hand, the old flaws of Android and its root architecture bring us a lot of pain every day.
- Do you think that the applied MVVM architecture “Model-View-ViewModel” occupies a leading position and is considered modern technology? Do we expect changes in this direction? What can be brought to this architectural approach?
- It is difficult to talk about the leading positions of any architectural approach. Everywhere has its pros and cons. If you look at how they look, work, and what is “under the hood” for most of the applications popular in the market, then there will be no doubt about the leading approach: “tyap-blunder-in-production”, so I do not consider MVVM to be especially popular. And in the Android world, unlike iOS, this is also a rather young direction, since DataBinding from Google became stable not so long ago.
- As far as I know, part of your report will be devoted to the MVVM template and its “life” in a reactive environment. Please tell us whether this will be a new look at the architecture of the application or a review of old approaches to designing with a new sauce.
- This will be our original view, not claiming to be the best and the most correct, it combines well-known solutions, but also has our own achievements. We do applications this way, and we really like it, we want to share this with our Russian colleagues, who have not yet left hopelessness to find an approach that would eliminate the struggle with the numerous limitations of the Android SDK and the application life cycle.
- Today, developers have enormous opportunities, at the same time a lot of pitfalls, and you can’t keep track of everything, especially in large projects. Don't you think that using Dependency injection (DI) is a great solution in this situation?
- Yes, DI is a great way to speed up refactoring. But you do not need to turn this, so to speak, into the DI of the brain and inject everything indiscriminately. We at 90Seconds, and even in our home projects love DI, we often implement it with Dagger2. And we also advise everyone to use this approach in their projects. There will be several reports on Mobius, including mine with Stepan, about the architecture being tested and allowing good code support.
- Thank you so much for the conversation. We will be glad to hear your report.
We are waiting for everyone at our presentation , it will be interesting!
Stepan Goncharov
- Stepan, good afternoon! Please tell us a little about yourself and about your work now.- Kind. If it’s very briefly about myself, then I began to be interested in Android development in 2008, before the official release 1.0, in the first half of 2009 I already had an application in the Android Market (few people already remember that Google Play was then called that) and a couple of other third-party markets. From advertising, I earned about $ 1,000 and bought my first Android phone to see how this application works on a real device. At the same time, as you already noticed, I got carried away with the creation of games, one of which later appeared in the Android Market and the App Store. Then I switched to the development of custom applications and after devoting 4 years to this, I realized that I wanted to try myself in product development. So I ended up as a team lead in one of Singapore startups, and then in 90 Seconds,
- In 2011, you released a series of articles on creating games that definitely attracted readers. Today there is a demand for these materials?
- Unfortunately, I have not written articles about game development for a long time. About a year ago, he began to add small articles on Medium , mainly about Kotlin and Android.
- I wanted to ask a question that relates directly to the topic of our conversation. Not so long ago, I saw a correspondence regarding Kotlin, and I really liked your answer “Fortunately for me Kotlin it is a Swiss Army Knife in Java world” (for me, Kotlin is a Swiss knife in the Java world). Do you really think Kotlin is a one-stop development solution?
- Yes, Kotlin is a unique tool that, despite its shortcomings, significantly improves productivity and expands the capabilities of developers, while still allowing you to easily work with almost any Java library.
A great example of using the data class and default parameters, an example of how to increase developer productivity . And one more option demonstrating work with lists .
- Please tell us about situations where the use of Kotlin can improve the quality of the code, its readability, and, possibly, save you from unnecessary checks for null.
- Indeed, one of the most noticeable differences between Kotlin and Java is Nullable types. The need to explicitly check for null significantly improves the quality of the code, but it is not a 100% guarantee of getting rid of NPE. One of my favorite Kotlin features is a set of extension functions for standard Java collections, which greatly simplify working with data and reduce the amount of code, which in turn facilitates its subsequent modification and reduces the number of potential errors. And, of course, delegates who, in combination with default implementations of methods in interfaces, allow you to use composition 100%, which is quite difficult to achieve in Java because of the need to write, and then maintain a huge amount of code.
-There is a lot of material on the network about the conciseness and compactness of the Kotlin code, everything is clear with this. But do not forget about the support of such code. Will a developer, for example, in Java, always quickly understand a project in Kotlin? What problems / subtleties do you see in the language that are unusual for, for example, Java / Scala?
- Although I started to get interested in Kotlin back in 2012, I still think that it will not be difficult for an experienced Java developer to deal with Kotlin, Denis just went through this recently, so he can tell in more detail. For beginner Java developers, everything is much more complicated, from my point of view, a deep knowledge of Java is simply necessary in order to begin to learn Kotlin.
Often, knowledge about the features of Kotlin helps to understand why a particular library does not work as expected. Of the subtleties, it is worth noting Annotation Processing , used by many popular libraries (for example, Dagger2, RxBindings) , which still causes some inconvenience, for example, the DataBinding Annotation Processor does not always correctly understand what type the method returns if the type is not explicitly specified in Kotlin code, or for example, Dagger2 will not work with generic types without @JvmSuppressWildcards annotations. Also, beginners will have to deal with the unusual view of stacktrace for inline functions and coroutine .
- I would like to touch upon another development topic for Android. We have been hearing and reading about the benefits of using for quite some time.RxJava in applications. It is interesting to hear your opinion about this library. I often see materials where they are not always uniquely positive about ReactiveX.
- Yes, you’re right, there will always be both haters and fans from this or that approach, rxJava is no exception. I am more in the second group, although I understand that the approach itself, like any other, has both advantages and disadvantages. But despite all the shortcomings, I would recommend at least thoroughly understanding the topic for each Android developer.
- How do you feel about the "continuation" of RxJava in the form of RxAndroid and RxBinding ? Do you use this functionality in your projects?
- As an RxKotlin contributorand authorRxDataBindings , I see great benefit in similar Rx libraries. And I use RxAndroid in each of my projects.
RxDataBindings can significantly reduce the amount of code required for the interaction of classes from the DataBindings library and rxJava2.
- To summarize our conversation, I would like to hear your opinion about the trends in Android development for the next couple of years. Will the movement continue towards reactivity, compactness, and code reduction?
- Definitely, the Android community is already tired of the verbosity of Java, especially watching how Apple promotes Swift. I think in the coming years we will see a rapid increase in the use of alternative JVM languages for Android development (Kotlin, Scala, Groovy, Ceylon, Clojure). Rx is likely to continue to strengthen its position as the main approach in mobile development; in the next couple of years, it can only compete with approaches based on the concept of corutin, but, unfortunately, only Kotlin supports them so far, and then in experimental mode.
- Thank you so much for the conversation. We look forward to your presentation.
We invite everyone to our report with Denis at the Mobius conference .