📜 ⬆️ ⬇️

Kotlin + Rx2: A reactive and functional approach to the development of mobile applications

The number of technologies, libraries is increasing every day, and you can often get lost in choosing a stack of technologies and architecture for starting or developing your mobile project. It is definitely possible to minimize risks, one of the options is to listen to the opinion of Android-development specialists.



That is why we turned to Denis nekdenis Neklyudov (Android GDE) and Stepan Stepango Goncharov, Android developers at 90Seconds.com. The interview will cover several important topics, from the architecture of the mobile application to the use of Rx libraries in projects. So, let's begin…
')

Denis Neklyudov


- Good afternoon, Denis! Tell me, please, what is the focus of your attention in the development context at the moment?

- Good day! Now I, like my partner in the performance on Mobius Stepan Goncharov, are developing a new mobile client for the Singapore 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 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 interview you talked about the status of the Google Developer Expert and what it means to you. One of the key phrases, in my opinion, was: “And also to engage in my favorite hobby: sharing knowledge with people at conferences, in podcasts and in articles.” Tell me, please, have you changed your mind about the need to spread information and promote ideas?

- I have not changed, and 30 episodes of our podcast on Android development , an excellent confirmation of this. I can share another problem I faced during these two years, being in the status of GDE. If you speak with the theme of “what’s new in the new Android”, then there are a lot of people who have read the documentation themselves, all 20 pages that you so neatly put into one convenient presentation, and go in the middle with the words: “Oh, well, this is me I could read it myself. ” And when you come up with a topic unknown to the majority, you tell it and see that only a small percentage of the audience understands what they are talking about, because they are absolutely not prepared, and there is no time for introductory material in the half-hour presentation. And not even the fact that the people who left with your first presentation will not leave the same with the second.

That's why we decided to record podcasts. It will be interesting to listen to everyone, because there we discuss problems of all levels, there both a beginner and an industry professional will find something useful for himself.

- To be aware of the latest events, changes - this is your credo? Does knowledge of future changes in the language affect adherence to a particular style of writing code, or are you a supporter of the use of the latest technologies?

- I am a supporter of maintaining balance. I can’t stand the extreme "we have the newest libraries, which are not even in release yet, time-tested approaches." And also I don’t like total conservatism, which covers people, for many years of experience of which more than a dozen cones crammed when trying to try something new. We must try to balance between the speed of development that business needs today and the possibility of scaling, expanding and maintaining other teams of the application that business needs tomorrow.

- All attention is now focused on Android Nougat, right? What kind of innovations were adopted by the developers positively, I think that during this period from the moment you left, you have already formed your opinion.

- In fact, what Nougat, what Marshmallow, that recently announced Android O Developer Preview are the organic development of Android Lollipop, not trying to change something radically in the SDK. On the one hand, this is good: to support the new version of the OS in the application, you do not need a lot of work. But on the other hand, the old drawbacks of Android and its root architecture bring us a lot of pain day by day.

- Do you think that the applied architecture of MVVM "Model-View-ViewModel" occupies a leading position and is considered a modern technology? Should we wait for changes in this direction? What can be brought into this architectural approach?

- It is difficult to talk about the leading positions of any architectural approach. Everywhere there are pros and cons. If you look at how they look, work and what is “under the hood” in most popular applications in the market, then there will be no doubt about the leading approach: “tap-off-in-production”, so I do not consider MVVM to be particularly popular. And in the Android world, unlike iOS, this is also a fairly new direction, since Google's DataBinding has become stable not too 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 this will be a new look at the architecture of the application or analysis of old approaches to the design under the new sauce.

- This will be our original view, which does not pretend to be the best and most correct, it combines well-known solutions, but it also has our own work. We make applications like this, and we really like it, we want to share it with our Russian colleagues, who have not yet left the idea of ​​hopelessness to find an approach that would save them from struggling with the numerous limitations of the Android SDK and the application life cycle.

- Today, developers have huge opportunities, at the same time a lot of pitfalls, and do not keep track of everything, especially in large projects. Doesn't it seem to you that using Dependency injection (DI) is an excellent solution in this situation?

- Yes, DI is a great way to speed up refactoring. But it is not necessary to transform this, so to speak, into the DI of the brain and inject everything indiscriminately. We at 90Seconds, and in our home projects we love DI, we often implement it with the help of Dagger2. And we also recommend everyone to use this approach in their projects. There will be several reports on Mobius about the architecture being tested and allowing for good support of the code, including mine with Stepan.

- Thank you so much for the conversation. Looking forward to hearing 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 your work now.

- Kind. In short, about myself, I began to be interested in developing for Android in 2008, even before the official release of 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 called that at the time) and a couple of other third-party markets. I earned about $ 1000 from advertising and bought my first Android phone to see how this application works on a real device. In parallel, as you have already noticed, I became interested in creating games, one of which later turned out to be in the Android Market and the App Store. Then I switched to developing applications for the order and, having devoted 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's startups, and then in 90 Seconds, where I had the rare opportunity to create a unique application from scratch using the most advanced technologies.

- In 2011, you released a series of articles on the creation of games that clearly attracted readers. Today there is a demand for these materials?

- Unfortunately, I haven’t written articles about game development for a long time. About a year ago, I started adding small articles on Medium , mostly about Kotlin and Android.

- I wanted to ask a question directly related to the topic of our conversation. Not so long ago, I saw the correspondence concerning Kotlin, and I really liked your answer “Fortunately for me, it’s a Swiss Army Knife in the Java world” (Kotlin for me is a Swiss knife in the world of Java). Do you really think Kotlin is a universal development solution?

- Yes, Kotlin is a unique tool, which, despite its shortcomings, significantly increases productivity and expands the capabilities of developers, while still allowing you to work with almost any Java library.
A great example of using data class and default parameters, an example of how to increase developer productivity . And another option that demonstrates the 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 null checks.

- Indeed, one of the most noticeable differences between Kotlin and Java is the Nullable types. Having 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 all-time favorite features of Kotlin is the set of extension functions for standard Java collections that greatly simplify working with data and reduce the amount of code, which in turn eases 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 quite a lot of material on the network about the brevity and compactness of the code on Kotlin, with this everything is clear. But do not forget about the support of such code. Does the developer always, for example, in Java, quickly understand the project in Kotlin? What problems do you see in the language that are unusual, for example, Java / Scala?

“Even though I started to be interested in Kotlin back in 2012, I still think that it’s easy for an experienced Java developer to deal with Kotlin, Denis just recently went through this, so he can tell in more detail. For Java developers, everything is much more difficult, from my point of view, a deep knowledge of Java is simply necessary in order to start developing Kotlin.
Often, knowledge about the features of Kotlin helps to understand why this or that 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 certain inconveniences, for example, DataBinding Annotation Processor does not always correctly understand what type returns the method, if in Kotlin code the type is not explicitly specified or for example, Dagger2 will not work with generic types without @JvmSuppressWildcards annotations. Also, beginners will have to deal with the unusual kind of stacktrace for inline functions and corutin .

- I would like to touch on another development topic for Android. We have been hearing and reading about the benefits of using RxJava in applications for quite some time. It is interesting to hear your opinion about this library. I often see materials where they do not always positively speak positively about ReactiveX.

- Yes, you are right, there will always be both haters and fans in one or another approach, rxJava is no exception. I am more of a 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 understand the topic to 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 a contributor to RxKotlin and the author of RxDataBindings , I see a great benefit in Rx-like libraries. And I use RxAndroid in each of my projects.
RxDataBindings allows you to significantly reduce the amount of code required for interaction between classes from the DataBindings library and rxJava2.

- Summing up a small summary of our conversation, I would like to hear your opinion on 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 Apple promote Swift. I think in the coming years we will see a rapid growth in the use of alternative JVM languages ​​for Android development (Kotlin, Scala, Groovy, Ceylon, Clojure). Rx will most likely continue to strengthen its position as the main approach in mobile development; in the next couple of years, it may be competing with approaches based on the concept of coroutin, 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.

Source: https://habr.com/ru/post/325836/


All Articles