Multiplatform projects with Kotlin. (Graphic: Shutterstock.com/Bella Melo)

Do not repeat yourself: After the paradigm Jetbrains wants to take multi-platform projects to a new level – without losing sight of the native development . This is behind the new Kotlin feature.

Crossplatform frameworks are nothing new. Especially in mobile development there are some approaches, as for Android and iOS at the same time an app can be written. But such frameworks usually come with strong limitations therefore. Be it the design of the user interface or the use of platform-specific technologies. That’s why many programmers continue to rely on completely native development. As a result, the UI can be designed without restrictions in the design language of the respective platform and the user can be completely satisfied. However, this has the disadvantage that repeats a lot of code for the different target platforms – just in a different programming language.

This is how multiplatform projects work in Kotlin

But Jetbrains wants to change a lot in the field: The Czech software company wants to share for multiplatform projects with Kotlin only the platform-independent logical source code. The remainder will continue to be natively developed for each platform with the appropriate SDKs, tools and design guidelines.

To do that, Jetbrains uses three modules. The most obvious is probably the commonmodule. Here, the platform-independent part described above is implemented. So everything has to do with data as well as the business and presentation logic. Also pretty obvious is the second  regular module. It integrates the user interface for the web client, Android or iOS as well as platform-specific APIs. The whole thing is done individually for each target platform, making the application 100 percent native to the user.

Then there would be another module called  Platform  left over. This creates a little bit the connection between the other two modules. Part of the  Common module are expected classes without the actual implementation – similar to interfaces. Only that the classes are far more powerful. For example, you can have constructors like normal classes.

expect class Foo(val name: String) {
  fun bar()
}

fun main(args: Array) {
  Foo().bar()
}

If you really want to implement the bar function for, let’s say, the Java Virtual Machine (JVM for short), another class is needed – but now in the Platform module. It could look like this:

actual class Foo actual constructor(val name: String)
  actual fun bar() {
    println("Hallo $name.")
  }
}

The principle of  Expect and  Actual does not only work for classes. Similarly, top-level functions or type aliases can be created. You can also find out how to write multiplatform projects in Kotlin yourself in the official documentation .

Multiplatform projects are still experimental

Multiplatform projects were introduced in the Kotlin version 1.2, which was released in November 2017, and have since been greatly enhanced. Nevertheless, the features are experimental for the time being and not mature. However, the basic concept is already clear and could change a lot in the coming months and years. Also from the point of view that Kotlin is increasingly becoming a universal programming language. Whether for Javascript, Android, the JVM, iOS or desktop – Kotlin can already be used everywhere.

With multi-platform projects, Jetbrains is now taking the next logical step, following the words of  Andrey Breslav, Chief Language Designer of Kotlin: “We chose our programming language expertise (seven IDEs in today’s market, and each is almost one) Compilers) and to create a language that people need “. Because with this concept, Jetbrains could simplify the way software is developed for many companies in the future. In many places there are tools for the web, the desktop, iOS and Android. All this could cover Kotlin in the future, with much of the code being easy to reuse.


Continue Reading...

Multiplatform projects with Kotlin. (Graphic: Shutterstock.com/Bella Melo) Do not repeat yourself: After the paradigm Jetbrains wants to take multi-platform projects to a new level –...

Read Post

Multiplatform projects with Kotlin. (Graphic: Shutterstock.com/Bella Melo) Do not repeat yourself: After the paradigm Jetbrains wants to take multi-platform projects to a new level –...

Read Post