client logo

6 August 2018

Kotlin - Latest Developments

Kotlin develops quickly! Last year brought us many changes and possibilities. Both in the community and in the language. Let’s summarize them.

 

First of all, the Kotlin community grows extremely fast and this growth accelerates. As Andrey Breslav - lead language designer of Kotlin - revealed in the podcast, in the year 2017 Kotlin team noted over 100 000 new Kotlin developers. When we talked in the middle of 2018, he revealed that they have already noted as many new developers in 2018. In the middle of the year! We can suspect that this growth is mainly due to Android community which not only announced Kotlin as a first class citizen but also moved Kotlin documentation examples to Kotlin and described Kotlin as a new way to develop Android applications. More and more Android developers and companies are migrating to Kotlin, but this is not the only source of new Kotlin developers. As JetBrains survey revealed, only 70% of Kotlin developers do Android development. Therefore we can conclude that at least 30% of Kotlin developers use Kotlin for a different kind of development. Probably the majority of them mainly does backend development. There are important reasons for that. Kotlin becomes a first-class citizen in Spring Boot, which is the most popular JVM framework. This two communities (Kotlin and Spring) work closely together. Kotlin coroutines, the feature which introduces important performance improvement in backend, is now highly supported in Spring. Although Spring is not everything. We can see growing popularity of Ktor framework, which is purely Kotlin framework for backend development. Kotlin is more and more popular for other usages too. Gradle allowed us to define configurations in Kotlin. Testing in Kotlin is also highly supported thanks to specification frameworks like Spek and great mocking libraries like MockK.

 

Kotlin is not only more and more popular but it also gives more and more capabilities. It is not a new fact that you can do JavaScript development in Kotlin (Kotlin/JS). Kotlin highly supports React development. What is a news is that Kotlin can be also compiled to native code (Kotlin/Native), so you can use this capability to make data analysis using C++ libraries or iOS development in Kotlin. There are already CLion and AppCode plugins that support iOS development in Kotlin. Having Kotlin on every platform is one thing, but what is more important we can make common modules - modules with code that can be used in all platforms (on Android, iOS, Web, backend etc.). This makes Kotlin truly multiplatform.

 

Kotlin languagechanged as well in last year. Kotlin 1.2 concentrated on multiplatform development and coroutines (they both required new modifiers and features). Kotlin was constantly improving stability by quickly resolving all problems found by community and improved tooling. Except that, Kotlin doesn’t change a lot. All key changes can be found here, but this is my favorites:

 

Now when we need a bounded reference to a function accessible using a receiver, we can omit this. So instead of this::foo, we can use just ::foo. This change was made to better support Spring which intensively uses bounded references to receivers.

 

Support for lateinit is not much better: such properties are allowed locally and reflection is much better
 

Array literals are now allowed in annotations:

 

@CacheConfig(cacheNames = ["books", "default"])

public class BookRepositoryImpl {

   // ...

}

 

Big changes in Kotlin itself were announced to be released in Kotlin 1.3. For instance, since this version capturing when subject in a variable is possible:

 

fun Request.getBody() = when (val response = executeRequest()) {

   is Success -> response.body

   is HttpError -> throw HttpException(response.status)

}

 

Experimentally, Kotlin also introduced a support for inline classes and unsigned integer types. What are inline classes? Class with exactly one property can be replaced during runtime with this property. This is what inline modifier does. See this class and usage:

 

val name: Name = Name("Mike")

fun capitalize(name: Name): Name = Name(name.value.capitalize())

 

Above code is compiled to the following implementation:

 

val name: String = "Mike"

fun capitalize(name: String): String = name.capitalize()

 

Inline classes give us an even lighter way to express a class (makes classes even cheaper in Kotlin) and they make it possible to introduce inline-only features into classes. Like, for instance, reified types.

 

As you can see, Kotlin community grows and Kotlin language evolves. Kotlin is a multiplatform language that is loved and used by more and more developers every year. Right now Kotlin is mainly associated with a language of Android development, but it’s rapid growth and popularization might signalize upcoming Kotlin revolution.

 

For more information visit our Kotlin Training course outlines:

Kotlin training course

Kotlin Best Practices training course


 

Case Study: Angular training makes a difference to customer engagement.

Find out more

VIEW ALL CASE STUDIES