RxSwift and Korutin in Kotlin - optional on mobile development from AGIMA and GeekBrains

RxSwift and Korutin in Kotlin - optional on mobile development from AGIMA and GeekBrains




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

This year, GeekBrains, within the framework of GeekUniversity, an online university for mobile development, began working with an interactive agency AGIMA, whose team is professional developers (they make complex high-load projects, corporate portals and mobile applications, that's all). AGIMA and GeekBrains have created an option for deep immersion in practical issues of developing mobile applications.

The other day we talked with Igor Vedeneev, an iOS specialist, and Alexander Tizik, who specializes in Android. Thanks to them, the mobile development option has been enriched with practical Kortlin . In this article, the developers talk about the importance of each direction for programmers.

Reactive Programming in iOS using RxSwift as an example



Elective teacher Igor Vedeneev: "With RxSwift your application will fly"

What information do students receive at the elective?

We tell not only about the capabilities of the framework, but also show how to use it in the classic MVVM + RxSwift combination. Several practical examples are also considered. To consolidate the obtained data, we write an application as close as possible to the field conditions of work. This will be a music search application using the iTunes Search API . There we will apply all the Best Practices, plus consider a simpler version of using RxSwift in the MVC paradigm.

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

RxSwift organizes work with event streams and connections between objects. The simplest and most obvious example is the bindings: for example, you can update the interface by simply setting new values ​​to a variable in the 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 a developer, knowledge of the framework is also a good plus in a resume, because understanding 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 more likely that the problem faced by the developer, has already been solved by someone. Also a large number of bindings out of the box. Moreover, RxSwift is part of ReactiveX. This means that there is a counterpart for Android, for example (RxJava, RxKotlin), and colleagues can talk to each other in the same language, 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 binding options are added. Since RxSwift is open source, you can follow all changes.Moreover, it is possible to add them yourself.

Where should I use RxSwift?

  1. Binding. As a rule, here we are talking about the UI, the ability to change the UI, as if responding to changes in data, rather than explicitly telling the interface that it is time to upgrade.
  2. Linking components and operations. Just an example. We need to get a list of data from the network. In fact, this is not such an easy operation. To do this, send a request, map the response into an array of objects, save it to the database and give it to the UI. As a rule, different components are responsible for carrying out these operations (we love and follow the principles of SOLID ?). Having such a tool as RxSwift at hand, it is possible to describe what the system will do, and HOW it will do it - it will be in other places. Due to this, better organization of the code is achieved and readability is increased. Relatively speaking, the code can be divided into the table of contents and the book itself.

Korutins at Kotlin



Elective teacher Alexander Tizik: "Modern development requires modern technical means"

What will be taught at the GeekBrains faculty within the branded quarter?

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

We will learn to write idiomatic code on coroutines, which solves practical problems and is understandable at first glance even without in-depth knowledge of how corortines are structured (which is not the case with libraries such as RxJava). We will also understand how to use more complicated concepts, such as the actor model, to solve more complex problems, such as data storage in the MVI concept.

By the way, more good news. While the elective was being recorded, the Kotlin Coroutines library update was released, in which the Flow class appeared - an analogue of the Flowable and Observable types from RxJava. The update essentially makes the feature complete korutinis from the application developer’s point of view. True, there is still a lot to develop: despite the fact that thanks to the support of korutin in kotlin/native it is already possible to write multiplatform applications on Kotlin and not suffer from the absence of RxJava or analogs in pure Kotlin, the support of korutin 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?

Korutiny give an excellent opportunity to write readable, supported and safe, asynchronous and "competitive" (concurrency) code. You can also create adapters for other asynchronous frameworks and approaches that can already be used in the code base.

How are Coroutines different from streams?

The Kotlin team calls the Cortina lightweight streams. Plus, the quorutine can return some value, because, in its essence, quartz is a suspended calculation. It does not directly depend on system streams, streams only play cortutins.

What practical problems can be solved with the use of Korutin, which can not or difficult to solve with the help of "clean" Kotlin?

Any asynchronous, parallel, "competitive" tasks are well solved with the help of coruntine - whether it be processing clicks from the user, 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 basic courses, too) are updated in accordance with changes in the external conditions. If there are important updates in languages ​​or frameworks, teachers will take this into account and modify the program. All this allows you to keep abreast of the development process, so to speak.

Source text: RxSwift and Korutin in Kotlin - optional on mobile development from AGIMA and GeekBrains