One of the first questions that many developers ask is why do we need another programming language?

Kotlin was created as an alternative language to a number of existing languages. Its goal is to be a statically typed language that works on multiple application platforms.

history of kotlin

Put more succinctly though, one of the founders of Kotlin,

Andre Breslav said, "The goal is to create "a better language than Java." Now that's not to cast any aspersions on Java, it's just that Java has been around for a couple of decades now and it was time to take what we've learned from that language, and implement things even better. Kotlin was originally announced back in 2011, and it took a number of years of development before it burst onto the scene as a production-ready language. Version one was released in 2016, and just a little over a year later, Google decided that Kotlin was in such great shape, that it could be used as a first-class citizen in the Android Echo system. So, beginning with Android Studio 3.0, Kotlin can now be used as your one and only programming language, when you're building your Android apps.You can create a mixture of code, using both Java and Kotlin, or you can stick to pure Kotlin. The most recent version of Kotlin is version 1.2 as of the time of this recording, and we can expect new versions to be released occasionally. But the creators of Kotlin are committed to backward compatibility, so as they release new versions, your existing Kotlin code should keep on working.

kotlin platforms

There are three editions of Kotlin: Kotlin for the Java virtual machine compiles to Java bytecode, Kotlin JS transpiles to to JavaScript code, and a newer platform, Kotlin Native, compiles to native binaries. As of the time of this recording, Kotlin Native was still in development and in early testing, but Kotlin for the JVM is completely stable and ready for production, and that's the edition that I'll be focusing on throughout this course.

kotlin Goals

The goals of Kotlin are many fold. First of all, one of the most important goals is to be concise. Java code has a lot of unnecessary declarations, key words, individual characters, and so on. These are redundant, and don't help with the expressiveness or the functionality of the programming language. So Kotlin tries to get rid of some of those declarations and key words. It also introduces new key words that are shorthand for boiler plate code that you might otherwise have to create in Java explicitly, and not trivially, semicolons are not required in Kotlin. Instead in Kotlin, a line feed is usually enough to tell the compiler that a statement ending has been reached. All these strategies lead to simply less code. You can accomplish common tasks with three quarters, two thirds or sometimes even less code than you might require in Java.

Kotlin Safe

Second, Kotlin is designed to be a safe language. It offers syntactical shortcuts that let you avoid entire classes of errors such as null pointer exceptions which in Java are all over the place. Java code is filled with null checks. If this variable is null do this, otherwise do that, and you can shorten that logic in Kotlin usually to a single character.

Also, the Kotlin compiler is really good at inferring variables. It is a statically typed language, it's not dynamic, but at compile time, most of the time you don't have to explicitly type your variables. The compiler figures it out for you, and this not only reduces the amount of code you have to type, but it also makes your code a bit safer.

kotlin Interoperable

Kotlin code is interoperable with whatever platform it's running on. Kotlin for the JVM is compiled directly to Java bytecode that runs on the Java virtual machine, but that code can be mixed with code that's written in Java or Groovy or Scala or any other JVM language. Also, a lot of your Kotlin code, can work exactly the same both on the JVM and in a web browser when it's transpiled to JavaScript. There are some differences, especially where you're relying on what are known as platform types; classes that are defined by the particular platform. But the vast majority of your Kotlin code will be the same.

kotlin tool friendly

Finally, Kotlin is designed to be tool-friendly. If you're programming in Kotlin in any Java-based platform, such as JEE or Spring applications, you'll probably be programming in IntelliJ IDEA. There's also a plug-in available for Eclipse if you prefer that environment, but IntelliJ IDEA and Kotlin are built by the same company, JetBrains. And so it's understandable that the Kotlin plug-in from JetBrains will give you the best support. If you're an Android developer, you'll go directly to Android Studio. Android Studio is based on IntelliJ IDEA Community Edition, and it inherits all that Kotlin support. That makes it possible to create brand new Android Studio projects that use Kotlin exclusively, or you can start introducing Kotlin code a little bit at a time into your existing projects. So that's the philosophy of Kotlin. It's more concise, it's a safer language, and it's tool-friendly, allowing you to get the work done with less code.

Kotlin 12-12-2018 05:51:37pmView: 1914

Categories: Kotlin

Comments

Leave a comment