Kotlin Programming Language

Introduction

"Kotlin is a statically typed programming language that runs on the Java virtual machine and also can be compiled to JavaScript source code or use the LLVM compiler infrastructure. Its primary development is from a team of JetBrains programmers based in Saint Petersburg, Russia.While the syntax is not compatible with Java, the JVM implementation of the Kotlin standard library is designed to interoperate with Java code and is reliant on Java code from the existing Java Class Library, such as the collections framework. Kotlin uses aggressive type inference to determine the type of values and expressions for which type has been left unstated. This reduces language verbosity relative to Java, which demands often entirely redundant type specifications prior to version 10.

As of Android Studio 3.0 (released in October 2017), Kotlin is fully supported by Google for use with their Android operating system, and is directly included in the IDE's installation package as an alternative to the standard Java compiler. The Android Kotlin compiler lets the user choose between targeting Java 6, Java 7, or Java 8-compatible bytecode."

https://en.wikipedia.org/wiki/Kotlin_(programming_language)

References

Tutorials

Samples

Should you switch from Java to Kotlin?

Pros

  • "Better Java" & "Java after Effective Java"

  • Syntax Sugar

  • Null safety & Immutability

  • Easy to pick up by Java devs

  • Spring Framework official support (and this support is much better than year ago)

  • Google Android Support and Google using it too

  • Data classes vs Lombok

  • Great IDE support - Intellij can convert Java to Kotlin - but you can use Kotlin with Vim, VSCode and others... but IntelliJ recommended

  • "when" pattern matching

  • less boilerplate

  • Maybe some devs with Kotlin will be better and more modern (?) - it would be good to create job ad with Kotlin and check feedback

  • Java Interoperability

  • Destructuring Declarations

  • It is possible to mix Kotlin & Java in same project

  • backed by Jetbrains

  • Gradle Kotlin Script (?)

  • Played with it and it is nice, also got some colleagues which are using it at their work and they like it

  • Got test libraries like Spek, KotlinTest... but you can use Spock or JUnit too

  • it is polish ketchup https://ketchupy.pl/ ;)

Cons

  • Most people will stick to Java

  • Java development will be slower but it will probably catch Kotlin features later. But switching back to Java will be easy.

  • "Better Java" - but still you need to learn it.

  • Mindset change (which is actually a pro to me) - about null safety and immutability - using Kotlin as java is kinda ugly

  • Switching from Kotlin to Java and from Java to Kotlin in multiple project is a little bit annoying

  • Less tools? Like static code analysis? Still there are detekt, ktlint and plugin for SonarQube or codebeat.com

  • Some compatibility Java problems

  • Still it is a some kind of risk and time investment

  • A litle bit slower compilation time (?)

More opinnions

Also... new things in Java 10 https://www.quora.com/What-is-new-in-Java-10/answer/Nick-Maiorano

Comparison to Java Programming Language

https://kotlinlang.org/docs/reference/comparison-to-java.html

"Some Java issues addressed in Kotlin

Kotlin fixes a series of issues that Java suffers from

  • Null references are controlled by the type system.

  • No raw types

  • Arrays in Kotlin are invariant

  • Kotlin has proper function types, as opposed to Java's SAM-conversions

  • Use-site variance without wildcards

  • Kotlin does not have checked exceptions

What Java has that Kotlin does not

  • Checked exceptions

  • Primitive types that are not classes

  • Static members

  • Non-private fields

  • Wildcard-types

  • Ternary-operator a ? b : c

What Kotlin has that Java does not

  • Lambda expressions + Inline functions = performant custom control structures

  • Extension functions

  • Null-safety

  • Smart casts

  • String templates

  • Properties

  • Primary constructors

  • First-class delegation

  • Type inference for variable and property types

  • Singletons

  • Declaration-site variance & Type projections

  • Range expressions

  • Operator overloading

  • Companion objects

  • Data classes

  • Separate interfaces for read-only and mutable collections

  • Coroutines"

Last updated