RxSwift and Coroutines in Kotlin - Mobile Development Elective from AGIMA and GeekBrains

RxSwift and Coroutines in Kotlin - Mobile Development Elective from AGIMA and GeekBrains

Knowledge is good, just great. But practice is also needed to be able to use the received data, transferring them from the status of "passive storage" to the status of "active use". No matter how good the theoretical training is, it still requires work “in the field”. This applies to almost any area of ​​education, including, of course, software development.

This year, GeekBrains, within the framework of the faculty of the online university GeekUniversity on mobile development, began working with the 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 elective for a deep dive into the practicalities of mobile app development.

The other day we spoke with Igor Vedeneev, an iOS specialist, and Alexander Tizik, an Android specialist. Thanks to them, the elective course in mobile development was enriched with practical a special course on the RxSwift framework и 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

RxSwift and Coroutines in Kotlin - Mobile Development Elective from AGIMA and GeekBrains
Elective teacher Igor Vedeneev: "With RxSwift your application will fly"

What information do students receive in the elective?

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

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

RxSwift streamlines work with event streams and relationships between objects. The simplest and most obvious example is bindings: for example, you can update the interface by simply setting a new value 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 on a resume, since an understanding of reactive programming, and in particular experience with RxSwift, is valued in the market.

Why choose this particular framework and not others?

RxSwift has the largest community. That is, it is more likely that the problem that the developer is facing 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 an analogue for Android, for example (RxJava, RxKotlin), and colleagues in the shop 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 features from new versions of Swift is added, new bindings are added. Since RxSwift is open source, you can follow all the changes. Moreover, it is possible to add them yourself.

Where should you use RxSwift?

  1. Bindings. As a rule, here we are talking about the UI, the ability to change the UI, as if reacting to data changes, and not explicitly telling the interface that it's time to update.
  2. Communication of components and operations. Just 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, you need to 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 performing these operations (we love and follow the principles SOLID?). Having at hand a tool like RxSwift, it becomes possible to describe WHAT the system will do, and HOW it will do it will be located in other places. It is due to this that a better organization of the code is achieved and readability is increased. Relatively speaking, the code can be divided into a table of contents and the book itself.

Coroutines in Kotlin

RxSwift and Coroutines in Kotlin - Mobile Development Elective from AGIMA and GeekBrains
Elective 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. As for 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 performance-demanding code to be reduced to a single, easy-to-understand style, gaining in the correctness of execution and performance.

We will learn how to write idiomatic coroutine code that solves practical problems and is understandable at a glance even without deep knowledge of how coroutines work (which cannot be said about libraries like RxJava). We will also understand how to use more complex 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 written, an update of the Kotlin Coroutines library was released, in which the class appeared Flow - analogue of types Flowable и Observable from RxJava. The update, in fact, makes coroutines feature complete from the point of view of an application developer. True, there is still room for development: despite the fact that thanks to the support of coroutines in kotlin/native, it is already possible to write multiplatform applications in Kotlin and not suffer from the lack of RxJava or analogues in pure Kotlin, support for coroutines in kotlin/native is not yet complete. For example, there is no concept of actors. In general, the Kotlin team plans to support more complex actors on all platforms.

Kotlin Coroutines - how do they help a Kotlin developer?

Coroutines provide a great opportunity to write readable, maintainable and secure, asynchronous and concurrency code. You can also create adapters for other asynchronous frameworks and approaches that may already be used in the codebase.

How are Coroutines different from threads?

The Kotlin team refers to coroutines as lightweight threads. Plus, a coroutine can return some value, because, at its core, a coroutine is a suspended calculation. It does not depend directly on system threads, threads only execute coroutines.

What practical tasks can be solved using Corutin, which ones cannot or are difficult to solve using “pure” Kotlin?

Any asynchronous, parallel, "competitive" tasks are well solved with the help of coroutines - whether it is 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 - using 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 should be said that both electives (and core courses too) are updated in accordance with changes in external conditions. If there are important updates in languages ​​or frameworks, teachers take this into account and modify the program. All this allows you to keep abreast of the development process, so to speak.

Source: habr.com

Add a comment