📜 ⬆️ ⬇️

Meet Kotlin 1.1: javascript, cortina and more

We are pleased to introduce you to Kotlin 1.1, the new version of the Kotlin programming language.


Kotlin 1.1

Our goal is to make an expressive statically typed language in which you can effectively write all the components of a modern application. Today's release takes two important steps in this direction.



First, JavaScript support has ceased to be experimental. All features of the language are available, a significant part of the standard library and, of course, the ability to interact with JavaScript code. Now the client part of the application can also be migrated to Kotlin, and there is no need to abandon the usual libraries and frameworks, such as React.


Secondly, there was support for corutin, which is a lightweight analogue of threads, which allows for a well-scaled application, while maintaining a large load on one machine. In addition, cortices greatly simplify writing asynchronous code, which is important for the “responsiveness” of the UI on all platforms.


More about these changes will be described below. Among other innovations, I would like to mention type aliases , bound callable references , destructuring in lambdas . A complete list of interesting changes can be found on our What's new page (look at the examples being run!).


Korutiny (Coutrograms)


Kortin in Kotlin allows you to write asynchronous code as easy as normal - synchronous.


Asynchronous code becomes more and more, and it is often quite difficult to write it. To facilitate this work, we added language-level support to Kotlin with just one primitive, suspending functions. Execution of such functions can be suspended without blocking any thread and resumed later. Moreover, the control over the logic of suspension and resumption of execution is fully owned by the author of the library, which allows the use of korutiny as a lightweight replacement of threads. Now, instead of expensive blocking flow, you can use almost free suspension of cortinis.


Very little was added to the syntax of the language (one modifier), but the libraries are provided with a huge scope for activities. For example, in the kotlinx.coroutines project , we have already implemented support for Rx, CompletableFuture, NIO, JavaFx, and Swing. Such libraries can (and are planned) to write for Android and JavaScript. Even constructs that are embedded in other programming languages ​​can be implemented in Kotlin in a library: for example, generators / yield from Python, channels / select from Go, or async / await from C #:


// runs the code in the background thread pool fun asyncOverlay() = async(CommonPool) { // start two async operations val original = asyncLoadImage("original") val overlay = asyncLoadImage("overlay") // and then apply overlay to both results applyOverlay(original.await(), overlay.await()) } // launches new coroutine in UI context launch(UI) { // wait for async overlay to complete val image = asyncOverlay().await() // and then show it in UI showImage(image) } 

Details in the documentation


Important note . Despite all the advantages that give Korutiny, their design is still relatively young. Therefore, it requires intensive testing in practice to make sure that we have done everything correctly. Therefore, in 1.1, the korutinas come out under the “experimental” flag . We assume that the language constructs are unlikely to change, however, in Kotlin 1.2 there may be changes in the API associated with the Korutins.


Javascript support


As we said above, all the features of Kotlin are now equally available for both JVM / Android and JavaScript (except for reflection, but we are working on it). This allows you to develop a web application entirely on Kotlin, which we successfully do in some products inside JetBrains. We plan to publish the relevant documentation and instructions in the near future.


Kotlin for JavaScript supports dynamic types for interacting with JavaScript code. For typed access to popular libraries, you can use the ts2kt converter with headings from DefinitelyTyped .


Details in the documentation


Tools


We are trying to release new functionality, not related to the syntax of the language, in intermediate releases. Here is the brightest thing that has appeared since Kotlin 1.0:



But we are not stopping and now we are preparing improvements in the toolkit for versions 1.1.x.


Kotlin's first year: community and distribution


In short, we are growing! Over 160 thousand programmers have used Kotlin over the past year. The number of lines on Kotlin in open source projects on Github has increased from 2.4 to 10 million. In the Kotlin slack channel at the time of release 1.0, there were 1,400 people - now 5,900. Every week around the world there are new meetings and user groups, organized by active members of the community. More and more new books and online courses are being published.


image


Kotlin is about equally popular among server-side and Android developers. Kotlin support appeared in the Spring Framework 5.0, as well as in vert.x 3.4 . Gradle and TeamCity use Kotlin-based DSL to program build scripts. A list of all major Kotlin projects and libraries can be viewed at kotlin.link .


A large number of world-famous companies began to use Kotlin in the product code: Amazon Web Services , Pinterest , Coursera , Netflix , Uber , Square , Trello , Basecamp, and many, many others. Corda is a distributed workflow system developed by a consortium of well-known banks (such as Goldman Sachs, Wells Fargo, JP Morgan, Deutsche Bank, UBS, HSBC, BNP Paribas, Société Générale) from the very beginning was developed at Kotlin . Kotlin is also used in Russian companies - for example, Avito, Rocketbank and Aviasales.


We are eternally grateful to all our users, contributors and active supporters in all corners of the world. Your support is very important to us!


Build your Kotlin 1.1 Event


The release is a good reason to meet other Kotlin users. We have prepared a set of materials that will help you organize such a meeting in your city: on March 23 we will broadcast a live meeting with representatives of the Kotlin team, plus you can get souvenirs and a set for Future Features Survey. More information and registration form here .


What's next


In order to make Kotlin a truly universal full-stack language, we continue to work on language and tool support for compiling common code for several platforms at once. This will allow you to write modules whose code is used both on the client side and on the server side. We are also continuing to improve the toolkit and support for third-party JavaScript libraries. Incremental compilation for JavaScript is already on the way, we will release it in one of the versions 1.1.x.


Java 9 support will appear by the release of the official version of this platform (this summer).


We expect to see a lot of reviews about korutinakh and we will, as they become available, work on improving the design, performance and libraries.


But, by and large, our next release will be primarily focused on the quality of the toolkit for existing language features, increasing productivity, expanding infrastructure, and fixing bugs. Kotlin is gradually moving into the category of key technologies for a large number of projects, and we respond accordingly to our growth.


PS Spreading Kotlin on all major platforms is a strategic direction for us. We can already run on servers, desktops, Android devices and browsers. In the foreseeable future, we plan to embrace the “world without virtual machines” and support such platforms as, for example, iOS and embedded systems. JetBrains is now working on this wonderful team of Kotlin Native, and we hope to show something interesting in a relatively short time.


How to try


As always, you can try Kotlin online right in your browser: try.kotlinlang.org .
Maven / Gradle : Use 1.1.0 as the compiler version number and standard library.
IntelliJ IDEA : Kotlin 1.1 support is already built into 2017.1, in earlier versions you just need to upgrade the plugin to version 1.1.
Android Studio : Install or upgrade plugin using Plugin Manager .
Eclipse : A new plugin is available in the Marketplace .
Command-line compiler can be taken from the release page on Github


Compatibility . In Kotlin 1.1, the language and standard library are fully backward compatible (modulo bugs): i.e. if something was compiled and started under 1.0, it will continue to work in 1.1. To facilitate gradual migration for large teams, we have provided a special compiler key that disables all new language features in 1.1. In this document, we described in detail all the details of migration.


')

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


All Articles