📜 ⬆️ ⬇️

Kotlin 1.2: common code for JVM and JavaScript

Yesterday the company JetBrains released the release of Kotlin 1.2. The new version is a big step towards making Kotlin the most convenient tool for developing all the components of a modern application.


In Kotlin 1.1, we officially released JavaScript support — the ability to translate Kotlin code into JS and execute it in a browser. In this version, we add to this the ability to reuse code between JVM and JavaScript . Now you can use the same business logic implementation in all components of your application — the backend, the front-end in the browser, and the Android mobile application. We are also working on libraries that help with this - in particular, on a cross-platform library for serialization.



Kotlin 1.2 is available out of the box in IntelliJ IDEA 2017.3 , which also comes out this week. If you are using Android Studio or an older version of IntelliJ IDEA, you can upgrade using the Tools | Kotlin | Configure Kotlin Plugin Updates.


Our external contributors made a great contribution to this release, and we would like to thank everyone who sent us feedback and bug reports, and especially to those who sent us pull-requests.


Multiplatform projects


Multi-platform projects allow you to assemble all the components of your application — the backend, the front-end, and the Android application — from a common code base. Such a project consists of common modules that contain platform-independent code, as well as platform-specific modules that contain code for a specific platform (JVM or JS) and can use libraries of this platform. In order to call the platform-specific code from the general module, you can specify the expected (expect) declarations - declarations for which all the platform-dependent modules must provide actual (actual) implementations .



More information on the use of multi-platform projects can be found in the documentation .


As already mentioned, we are also working on libraries that help transfer code to common modules:



Please note that support for multi-platform projects is released in experimental status. This means that it is possible to write such projects now, but in the future we may need to change its design (if this happens, we will provide tools for migrating existing code).


Compilation performance


In the course of working on version 1.2, we put a lot of effort into making the compilation faster. We have already achieved acceleration of about 25% compared with version 1.1, and we see great potential for further optimizations, which we plan to release in updates 1.2.x.


The graph shows the difference in compile times for two large projects in JetBrains using Kotlin:


Other language and library improvements


The new version also includes less significant improvements in the language and standard library:



More complete information about changes in the language and the standard library can be found in the document What's new in Kotlin 1.2 .


Kotlin worldwide


Since the release of Kotlin 1.1 in March of this year, the spread of its use around the world has greatly expanded. The climax was KotlinConf , our first conference, which we held in San Francisco on November 2-3, and which was attended by about 1,200 of our users. You can view the records of all the reports on the conference website .


Kotlin has also become an officially supported development language for Android. Kotlin-plugin included in the delivery of Android Studio since version 3.0, and on the Android website you can find official examples and style guide . Already, Kotlin is used by more than 17% of projects in Android Studio , including many applications of both the brightest startups and Fortune 500 companies.



On the server side, there was a release of the Spring Framework 5.0 with a large number of features for Kotlin support , and vert.x officially supports Kotlin since release 3.4.0. In addition, support for Kotlin build scripts is already included in the Gradle package, and the Gradle Kotlin DSL project is already close to release 1.0.


The number of lines of code in open-source repositories on GitHub has exceeded 25 million. And on Stack Overflow, Kotlin is simultaneously one of the fastest growing and least disliked languages .



The growth of communities around Kotlin is also impressive. There are more than 100 Kotlin user groups around the world, and there are so many reports about Kotlin that we can hardly keep track of them all - but for those we know about, the map gives a good idea of ​​how common Kotlin is.



For those who are just starting to use Kotlin, more and more books are available (including our own “Kotlin in Action” , which has already been translated into Russian , Japanese , Chinese, and Portuguese ), online courses, self-help books, and other resources .


Chat with the team: webinar and Ask Me Anything on the red


To tell you more about the new release, we will hold a webinar on the development of multiplatform projects with the help of Kotlin 1.2 on December 7, at 8 pm in Moscow. Do not forget to register; The number of participants is limited!


In addition, our team will conduct an AMA (Ask Me Anything, open interview) on Kotlin Reddit on December 5th. We will start at 2 pm in Moscow and will answer your questions within 24 hours.


How to upgrade


As always, you can try Kotlin directly in your browser, on the site try.kotlinlang.org



Compatibility: In Kotlin 1.2, the language and the standard library are backward compatible (modulo bugs) : code that was compiled and worked in versions 1.0 and 1.1 will also work in version 1.2. In order for large teams to switch to the new version gradually, we added the compiler option, which disables the ability to use new features of the language and library. Information about possible difficulties can be found in the documentation .


Have a nice Kotlin!


')

Source: https://habr.com/ru/post/343500/


All Articles