# Kotlin (Language)

## Summary


Kotlin is a next-generation programming language developed by JetBrains. It combines both object-oriented and functional features. It's focused on interoperability, safety, clarity and tooling support. It can be used for server-side, desktop or mobile apps. 

It's statically typed like Java, C, and C++. It's also fully compatible with Java but has a much simpler syntax. Google officially supports it for the Android platform and therefore Android apps can be written in Kotlin. Kotlin has multiplatform support, which means that code can be reused across Android, iOS or Web. 

It's open sourced under Apache 2 License. It's managed by the *Kotlin Foundation*.

## Discussion

### In what application areas is Kotlin most suitable?

Diverse set of apps can be built with Kotlin since it's a general-purpose language. It can be used to build mobile apps such as Android apps. Server-side apps can be built with Kotlin. Wherever Java is used for enterprise apps, such apps can be migrated to Kotlin. Since Kotlin can be compiled to JavaScript it can be used for web app development. 

Kotlin uses two file extensions: `.kt` for object-oriented programming and `.kts` for command-line scripting. This suggests that Kotlin can be used for scripting. Kotlin also has an interactive shell. This is useful for learning or clarifying doubts since results of code execution can be seen right away. 

In the real world, adopters of Kotlin include Pinterest, Gradle, Evernote, Corda, Coursera, Uber, Trello, Kickstarter, Square, and many more. 


### What's the difference between Kotlin and Java?

While there are differences, it's important to first note that Kotlin is compatible with Java. Kotlin code can be mixed with Java and can call existing Java libraries. IDEs also support automated conversion of Java code to Kotlin code. This makes the transition from Java to Kotlin a lot easier for existing projects. Since Kotlin targets JVM, Kotlin `.kt` files compile to `.jar` files.

Here are some reasons why it makes sense to move to Kotlin: 

    + **Learning Curve**: Kotlin has a simpler syntax and therefore easier to learn.
    + **Development Environment**: Kotlin has excellent IDE support, including IntelliJ IDEA and Android Studio. Compilation is fast, sometimes faster than Java. Similar support is lacking in Scala.
    + **Concise**: Kotlin does more with less code. Strong type inference is one reason. Java has always been known for its verbosity.
    + **Performance**: With Kotlin’s support for inline functions, code often runs faster.
    + **Safe**: Kotlin avoids NullPointerException. Since you write less code, there's less chance of introducing errors.
    + **Multiplatform**: Though initially created for JVM, Kotlin can be used for front-end development and even native apps.

### Could you mention some key features of Kotlin?

Here are some features of Kotlin: 

    + **Extensions**: Add extra functionality to an existing component.
    + **Higher-order Functions**: Functions themselves can be arguments to or returned from other functions.
    + **Interoperable with Java**: Kotlin code can be called from Java code and vice versa.
    + **Null Safety**: Objects are null safe by default so that nasty null pointer exceptions are avoided.
    + **Smart Cast**: Object is automatically cast to a desired type.
    + **Default Arguments**: Java took the approach of function overloading instead.
    + **Named Arguments**: Makes code more readable and order of arguments can be changed.
    + **Multi-value Returns**: Returned values can be unpacked into separate variables using *destructuring declaration*.
    + **Data Class**: Gets rid of the more verbose getters and setters in Java.A JetBrains survey from 2017 showed that three features are highly requested: collection literals, Single Abstract Method (SAM) conversions for Kotlin interfaces, and truly immutable data. JetBrains makes no promise if and when these features might be available. There are also features that developers don't want: accessing private members from tests, collection comprehensions, and static members in classes. 


### What resources are available for a Kotlin beginner?

Start by reading some examples in Kotlin Playground. For more in-depth information, read the official Kotlin documentation or tutorials. To learn by solving short exercises, Kotlin Koans is recommended. It's a series of exercises that will help you learn Kotlin step by step.

Kotlin style guide is an essential read. There's also a Kotlin for Android style guide.

For latest news, follow the Kotlin blog or the weekly mailing list. Links to other community resources such as podcasts, talks and Slack channels are available online. 

## Milestones

Jul  
2011

JetBrains unveils Kotlin at the JVM Language Summit. It's a new language for the Java Virtual Machine (JVM). The team is lead by Dmitry Jemerov and they have been working on it for almost a year. Since JetBrains makes development tools, work on IDE support for Kotlin happens in parallel with language design and evolution. JetBrains engineers later comment that although Scala was popular, it wasn't as fast or simple as desired. Groovy and Clojure had different programming paradigms. 

Jan  
2012

Dr. Dobb's Journal names Kotlin as the Language of the Month. 

Feb  
2012

JetBrains open sources the project under the Apache 2 License. This includes the compiler, Ant/Maven integration tools, IntelliJ IDEA plugin and enhancements to basic Java libraries. 

Feb  
2016

Kotlin v1.0 is released. Future releases will remain backward compatible with v1.0, thus showing that Kotlin is mature. 

May  
2017

At Google I/O 2017, Google announces support for Kotlin on Android. Until then, Android supported only Java and C++. It's mentioned that Expedia, Flipboard, Pinterest, and Square are among those already using Kotlin in production. Android support marks a turning point in Kotlin adoption. For example, by November 2017, number of lines of code on GitHub rose from 5 million to 25 millions. 

Nov  
2017

Kotlin v1.2 is released. In v1.1 it was possible to compile Kotlin to JavaScript and run within a browser. With v1.2, it's possible to share code between JVM and Javascript platforms. Regular updates to v1.2 are made. In September 2018, v1.2.70 is released. 

Oct  
2018

Kotlin v1.3 is released. *Coroutines* is now a stable feature and useful for writing non-blocking code. To compile code directly to native binaries, *Kotlin/Native* is released as beta version. To reuse code across platforms, *multiplatform* features remains experimental but gets many updates. 

Nov  
2018

Kotlin team releases version 1.0 of **Ktor**, a web framework built in Kotlin. It's good for building asynchronous servers and clients in connected systems. Thanks to coroutines, complex asynchronous constructs can be expressed as sequential code. It's claimed that Ktor is already running at scale in many production systems.