Kotlin is a programming language: what is it used for, pros and cons

When creating a new language, the developers took into account the successful solutions of their colleagues, as well as common problems or inconveniences that programmers usually face. It is not surprising that the finished product quickly earned recognition from the developer community, and to this day is the official and most popular language for Android applications. JetBrains also provided cross-platform compilation and created the integrated development environment IntelliJ IDEA. In addition to it, Kotlin is supported by many other popular IDEs:

Android Studio;

Eclipse (support via plugin);

Visual Studio Code (support via plugin).

How popular is Kotlin and why?
Since the Google I/O 2019 conference, Google has been strongly recommending writing new Android applications in Kotlin, especially since the universal Firebase platform, the most popular Google Maps/Places/Home services, many Google Play applications, applications and services of others are written on it. well-known companies. Examples that need no introduction include:

Ozon (mobile application written);

Uber (mobile application written);

Pinterest (one of the first to rewrite the code);

Atlassian (Jira cloud services);

Adobe (server solutions).

The popularity of the language is largely due to the flexibility and safety of working with it, relatively simple syntax, compatibility with older Java bases, the possibility of cross-platform compilation, and development of server applications. In addition, this is a free Open-Source product. The large developer community with active support from Google is trending upward. New extensions and libraries are designed to make development easier and improve optimization (there are problems with compilation speed on large projects, even compared to Java).

For example, the new KSP plugin, which replaced kapt, allows you to write your own optimizing plugins for the compiler. Using annotations, you can automate routine processes, reducing development time and increasing code quality and security. According to the creators, ideally KSP is capable of working 2 times faster than its predecessor. With some libraries, such as Room, we actually noticed an increase in performance.

Benefits of Kotlin Programming
This language is object-oriented and statically typed at the same time. There are already certain advantages associated with this. Static typing involves determining the types of variables at compile time. During programming, the type of a variable is declared explicitly (smart casts simplify this process by automating casting to the type) and you get feedback about the data types during compilation. Such inspection prevents errors and improves code security.

For example, the type system avoids the NullPointerException error. This is achieved by introducing nullable and non-nullable data types, which explicitly indicate whether the value can be null. Safe operator “?” initiates checking and processing of null values, can call methods, access fields, or perform other operations on variables that may contain null, without the risk of throwing a NullPointerException.

And in object-oriented programming there is a concept where an object is an instance of a class that combines data (fields) and methods that operate on this data. This paradigm provides the principles of encapsulation, inheritance and polymorphism, which makes the code more organized, reusable, and easier to maintain.

For example, a class with the “sealed” modifier combines all its subclasses within one hierarchy, eliminating unnecessary expansion of classes in other parts of the code. If it is already used with a “when” expression, and you add a new subclass, the compiler will warn you that the new class is not taken into account in this “when”.

Strengths include support for functional programming. These are: anonymous functions, including those with lambda expressions, for simply passing a function as an argument; higher functions that take other functions as an argument or return them as a result; extensions to add new functionality to existing classes without creating subclasses; immutable (unchangeable) collections corresponding to the functional programming style.

And of course, Kotlin multiplatform (KMP) is a technology developed by the same JetBrains that allows one developer to write applications for different platforms (mobile, web, desktop, server development). In the context of mobile, this allows the programmer to immediately write general code for Android and iOS. There is integration with Android Studio and Xcode, platform-specific modules for implementing the capabilities of different platforms.

The main advantages can be briefly listed as follows:

Multiplatform (compilation/transpilation in Native/JS);

Type safety;

String templates;


Concise, intuitive syntax;

Coroutines built into the language itself rather than as a library function;

Convenient work with exceptions and collections;

Data classes with auto-generation of standard methods;

Extensibility of classes without the need for inheritance;

Fully compatible with Java.

Disadvantages of Kotlin
There are also disadvantages. As already mentioned, the community often criticizes Kotlin for its low compilation speed in large projects. For some, this is simply annoying, but for others, the delays are critical. The compiler plugin does not always cover the problem, but it is not always the case. Different libraries show different compatibility with the plugin. New optimization solutions, I would like to believe, will come, as happened with the introduction of Kotlin in Android Studio, where performance problems were resolved over time.

Another problem is the dynamic standard library. In any case, this is a problem for programmers working on platforms with limited support for dynamic libraries or in scenarios using built-in libraries at the system level.

The size of binary files created in the compiler is usually slightly larger than in Java, although this is explained by the inclusion of additional libraries. Not so much a disadvantage as a factor that sometimes needs to be taken into account.

Delayed initiation of a variable before the first access to it (lateinit) can cause critical errors in the program. This is typically used for variables with data types that cannot be initialized in the constructor. Such a variable cannot be null, otherwise, when trying to access it before initiation, we will receive a UninitializedPropertyAccessException. Use with caution - only if you are sure that the variable will be initialized before use.

Where should Kotlin be used?
Of course, the first thing that comes to mind is developing applications for Android, because this is the official programming language for this platform, but Kotlin is not the only one that lives on Android. The scope of its application is actually much wider - from writing scripts to developing games.

In addition to writing Android applications, you can use the language:

In creating iOS applications. Of course, this is fraught with limited support for iOS libraries and problems with integration with the XCode IDE, but in general this possibility exists and it is appropriate to implement it if deep integration with the iOS ecosystem is not needed;

In server development. Creating a server application is a doable task for Kotlin. The language contains libraries useful for processing asynchronous operations on the server, and is supported by well-known frameworks (Spring, Ktor, Vert);

In the development of Desktop applications. You can create cross-platform desktop applications using the JavaFX library;

In data analysis, data science. It is advisable to use it in this area as well. Compatibility with Java facilitates work in an ecosystem of data analytics tools such as Apache Spark.

To summarize, I will say that although Kotlin’s capabilities are currently relevant primarily for creating Android applications, its multiplatform nature classifies the language as universal, and syntactic sugar, coding security and a rich selection of functions often motivate a novice programmer to learn this particular language.
Made on