Kotlin is a programming language created by JetBrains. One year after the release of its first official version in 2016, it has appeared in the top 50 of TIOBE ranking (programming languages popularity index).
Moreover, in just 6 years Kotlin has supplanted Java and become an important tool for Android developers. How did it happen? What are the benefits and flaws of Kotlin? Let's find out.
WHAT IS KOTLIN?
Kotlin is a statically typed cross-programming language based on the Java Virtual Machine. But unlike Java, where programs are built on classes, the basic building block of a Kotlin program is a function. However, Kotlin also supports an object-oriented approach to programming. It is often mentioned as the successor of Java in modern programming.
WHY DO WE NEED ANOTHER LANGUAGE INSTEAD OF JAVA?
There are two answers to this question.
in 2017, about a million of programmers who used the Kotlin language, required Android support. Google went to meet the developers and made Kotlin a priority language on Android.
Since 2010, Oracle has been suing Google over the use of Java in the Android system. Oracle demanded billions of compensations and won the court case three times: in 2012, 2014 and 2015. The case was not closed because Google refused to pay that much.
In 2016, the lawsuit grew to nine billion, but the court sided with Google. The case has been hanging since 2017, and Google is gradually transferring the entire Android infrastructure from Java to Kotlin.
WHAT IS THE KOTLIN USED FOR?
The scope of Kotlin programming language implementation is quite wide:
- mobile applications for Android and iOS, including cross-platform ones;
- web applications (both the server part and the interface);
- desktop applications;
- big data processing software.
- backend –Java and Kotlin compilation is provided in one project. Individually, Kotlin and Java are compatible by default;
- multiplatform programming – there are technologies for developing interfaces in React, creating a server-side HTTP API in Ktor, and adapting Android applications to the iOS operating system.
Today, it is mainly used to develop Android applications. In 2017, Kotlin received official support from Google, and in 2019 was declared a priority language for developing Android applications.
According to Kotlin creators, over the years of its existence Java has accumulated a lot of bad decisions. Therefore, they tried to consider all the shortcomings of Java and other programming languages to make the syntax of the new language as concise and convenient as they could.
For developers, it basically means that Kotlin code is easier to read. In some cases, it can be dozens of lines shorter than, for example, in Java.
MAIN BENEFITS OF KOTLIN
- Kotlin is fully compatible with Java.
It means that you can call functions declared in Java code directly from Kotlin code and vice versa, including using a large number of existing Java libraries.
- Any Java framework can be used in a Kotlin program.
Kotlin can also be integrated with build systems such as Maven and Gradle.
This is one of the main factors why more and more developers choose Kotlin.
- Kotlin is null-safe.
The creators of the language did everything to make NullPointerException a thing of the past. These are some of the most common exceptions and are nearly impossible to track down at compile time. Therefore, errors will only occur while the program is running.
- Extension functions.
Kotlin allows you to change the functionality of existing classes without class inheritance. This is a handy tool that allows you to increase the readability of your code. To declare an extension function, you need to prefix its name with the extension type.
- Kotlin is open source.
Kotlin code is open to programmers, and its implementation in the project is also free. Open source makes it easy to find problems. Kotlin developers are known to listen to third-party developers and make changes suggested by the community.
- Easy to teach.
Many people note that Kotlin is easy to learn and can be a programming language for beginners.
MAIN DISADVANTAGES OF KOTLIN
- Compilation speed.
There are problems with the code compilation speed. It is not necessarily a constant fault (sometimes compilation is even faster than in Java) but these moments can be frustrating.
- A small number of tutorials.
The community of Kotlin developers is confined; there are not so many publications, especially for "dummies".
- A small number of libraries in Kotlin.
The language is still quite young. Although this disadvantage is compensated by full compatibility with Java – you can use many of its existing libraries.
IN A NUTSHELL
Today Kotlin is officially the main programming language for developing Android applications.
As long as big companies – Uber, Netflix, Pinterest, Coursera – are working with Kotlin, it will become more widely implemented in both web and desktop applications. Therefore, in the next few years we can probably see Android developers using it one way or another.