RxSwift and Coroutines at Kotlin - optional mobile development from AGIMA and GeekBrains

    Knowledge is good, just great. But we also need practice in order to be able to use the data obtained, transferring them from the status of “passive storage” to the status of “active use”. No matter how good theoretical training is, more work is required “in the field”. The foregoing applies to virtually any field of study, including, of course, software development.

    This year, GeekBrains, as part of the department of mobile development at GeekUniversity online university, began working with the interactive agency AGIMA, whose team is professional developers (doing complex high-load projects, corporate portals and mobile applications, that's all). AGIMA and GeekBrains have created an elective for deep immersion in the practical issues of mobile application development.

    The other day we talked with Igor Vedeneev, an iOS specialist, and Alexander Tizik, who specializes in Android. Thanks to them, the elective on mobile development was enriched by a practical special course on the RxSwift framework and coroutines in Kotlin . In this article, developers talk about the importance of each direction for programmers.

    Reactive programming in iOS using RxSwift as an example

    Optional teacher Igor Vedeneev: “With RxSwift your application will fly”

    What information do students receive at the elective?

    We not only talk about the capabilities of the framework, but also show how to apply it in the classic MVVM + RxSwift bundle. Several practical examples are also considered. To consolidate the received data, we write an application that is as close as possible to the field working conditions. It will be a music search application using the iTunes Search API . There we will apply all Best Practices, plus we will consider a simpler option for using RxSwift in the MVC paradigm.

    RxSwift - why this framework for iOS-programmer, how does it make life easier for the developer?

    RxSwift streamlines work with event streams and relationships between objects. The simplest and most obvious example is binders: for example, you can update the interface by simply setting new values ​​in a variable in viewModel. Thus, the interface becomes data-driven. In addition, RxSwift allows you to describe the system in a declarative style, which allows you to streamline the code and improve readability. All this helps to develop applications more efficiently.

    For the developer, knowledge of the framework is also a good plus in the resume, since an understanding of reactive programming, and especially experience with RxSwift, is appreciated in the market.

    Why choose this framework, and not others?

    RxSwift has the largest community. That is, there are more chances that the problem that the developer is facing has already been solved by someone. Also a large number of binders out of the box. Moreover, RxSwift is part of ReactiveX. This means that there is an analogue for Android, for example (RxJava, RxKotlin), and colleagues can speak the same language with each other, despite the fact that some work with iOS, others with Android.

    The framework is constantly updated, minor bugs are fixed, support for chips from new versions of Swift is added, new binders are added. Since RxSwift is open source, you can follow all the changes. Moreover, it is possible to add them yourself.

    Where to use RxSwift?

    1. Bindings. As a rule, here we are talking about UI, the ability to change the UI, as if reacting to data changes, and not explicitly telling the interface that it is time to update.
    2. Link components and operations. Immediately an example. We need to get a list of data from the network. In fact, this is not such a simple operation. To do this, send a request, map the response to an array of objects, save it to the database and send it to the UI. Responsible for performing these operations, as a rule, are different components (do we love and follow the principles of SOLID ?). Having at hand a tool like RxSwift, it becomes possible to describe WHAT the system will do, and HOW it will do it - it will be in other places. It is due to this that the best organization of the code is achieved and the readability is increased. Relatively speaking, the code can be divided into a table of contents and the book itself.

    Coroutines in Kotlin

    Optional teacher Alexander Tizik: “Modern development requires modern technical means”

    What will be taught at the GeekBrains faculty as part of the branded quarter?

    Theory, comparisons with other approaches, practical examples in pure Kotlin and in the Android application model. With regard to practice, students will be shown an application in which everything is tied to coroutines. The fact is that most applications are continuous asynchronous and parallel computing. But Kotlin coroutines allow confusing, heterogeneous or overly complex and demanding in terms of performance code to be reduced to a single, easy-to-understand style, gaining in correct execution and performance.

    We will learn how to write idiomatic code on coroutines, which solves practical problems and is understandable at first glance even without deep knowledge of how coroutines work (which cannot be said about libraries like RxJava). We’ll also understand how to use more complex concepts, such as an actor model, to solve more complex tasks, such as the data warehouse in the MVI concept.

    By the way, more good news. While the optional was being recorded, an update was made to the Kotlin Coroutines library, in which a class appeared Flow- an analog of types FlowableandObservablefrom RxJava. The update essentially makes the coroutines feature complete from the point of view of the application developer. True, there is still much room for development: despite the fact that thanks to the support of coroutine in kotlin / native, it is already possible to write multi-platform applications in Kotlin and not suffer from the absence of RxJava or analogues in pure Kotlin, support for coroutine in kotlin / native is not yet complete. For example, there is no concept of actors. In general, the Kotlin team has plans to make support for more complex actors on all platforms.

    Kotlin Coroutines - how do they help the Kotlin developer?

    Coroutines provide an excellent opportunity to write readable, supported, and safe, asynchronous, and “concurrency” code. You can also create adapters for other asynchronous frameworks and approaches that can already be used in the code base.

    How do Coroutines differ from streams?

    The Kotlin team calls coroutines lightweight flows. Plus, coroutine can return some value, because, in essence, coroutine is a suspended calculation. It does not depend directly on system threads, threads only execute coroutines.

    What practical problems can be solved using Corutin, which cannot or are difficult to solve with the help of “clean” Kotlin?

    Any asynchronous, parallel, "competitive" tasks are well solved with the help of coroutine - whether it is processing user clicks, going to the network or subscribing to updates from the database.

    In pure Kotlin, these tasks are solved in the same way as in Java - with the help of thousands of frameworks, each of which has its pros and cons, but none of them has support at the language level.

    As a conclusion, it is worth saying that both electives (and the main courses too) are updated in accordance with changes in external conditions. If important updates appear in languages ​​or frameworks, teachers take this into account and modify the program. All this allows you to keep abreast of the development process, if I may say so.

    Also popular now: