Kotlin 1.2 Released With Cross Platform Support
Written by Mike James   
Thursday, 30 November 2017

JetBrains has just announced the release of Kotlin 1.2 and it is already supported in Android Studio 3. What's new and what's missing?

Kotlin has become an important language since Google adopted it as the alternative to Java in Android Studio. It really makes Android programming easier by reducing the need for long chunks of boilerplate code that the average programmer just doesn't get, or perhaps more accurately doesn't bother understanding at a deep level. There is an old saying in physics that you don't ever really get to understand anything, you simply get used to it. So it is with many aspects of a writing Java. You may have understood it once, but these days you simply let the IDE generate it for you.

Kotlin 1.2 has a new feature which in the past might have elicited a bit of a yawn. Another Java compatible language extends its reach into areas not many are going to take advantage of. The big difference is that with Kotlin as the language of Android it suddenly is worth considering it in other environments if only because your skills transfer.

The new feature is multi-platform projects. At the moment Kotlin supports the JVM, JavaScript and Native code as its three targets. In this new version you can create projects that can run on the JVM or JavaScript. There are common modules which work on either platform and then platform modules which are specific to the target.

 

kotlinplatform

 

This doesn't sound that amazing, but the clever part it that the common modules can bind to the platform dependent modules by "expected and actual declarations". This allows the same backend logic to access the same data via different UIs. For example, if the common module has:

expect fun hello(world: String): String

then it can make use of the function hello but it will be supplied by one of the platform modules, e.g on the JVM:

actual fun hello(world: String)

It isn't a perfect solution, but it is direct and easy to understand and JetBrains is working on common libraries that can be used in common modules.

A good improvement is a 25% speedup of the compiler:

kotlinspeed

JetBrains promises more speedups in decimal point updates.

Language changes are thin on the ground and mostly this is a good thing - a stable language is important - but the announcement lists: 

  • A more concise syntax for passing multiple arguments to an annotation (array literals);
  • Support for the lateinit modifier on top-level properties and local variables, as well as checking whether a lateinit variable is initialized;
  • Smarter smart casts and improved type inference in certain cases;
  • Compatibility of the standard library with the split package restrictions introduced in Java 9;
  • New kotlin.math package in the standard library;
  • New standard library functions for working with sequences and collections, including a set of functions for breaking a collection or sequence into potentially overlapping groups of a fixed size.

Of course, all of this should be backward compatible. Some enhancements that were not listed in the announcement but are worth knowing about are:

  • You can now use default values for parameters in inline functions.
  • You can now use the reference operator with methods without having to use this i.e. you can write ::method rather than this::method.

Sadly coroutines are still experimental even though they were introduced in 1.1. When this feature, complete with async and await, make it into the final build it will make a great difference - to Android programs in particular.

The announcement also provides a look at how well Kotlin is doing:

kotlingrowth

The steep increased occurred when Google announced Kotlin as an Android language.

 

More Information

Kotlin 1.2 Released: Sharing Code between Platforms

Related Articles

The Programmers Guide To Kotlin - Type

Android Studio 3.0 Released

Kotlin Begins Its Takeover Of Android

New Kotlin Style Guides Unveiled

Kotlin - New Language For Android

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

 

Banner


nginx Core Developer Announces New Fork
23/02/2024

One of the core developers of nginx has said he is no longer working on the development of the popular and widely used nginx web server, and is instead working on a new fork. Maxim Dounin release [ ... ]



Generative AI Training For All On Coursera
04/03/2024

Generative AI is on the loose, getting into business and commerce as well as into art, poetry and coding. Already useful, it  will become ever more useful as long as we use it properly. Coursera  [ ... ]


More News

raspberry pi books

 

Comments




or email your comment to: comments@i-programmer.info

<ASIN:1871962536>

Last Updated ( Thursday, 29 August 2019 )