Experience the power of kotlin and learn why it is more liberating than java in terms of Android development.
Google announced support for kotlin in Android at Google I/O 2017. It reinforced how important Kotlin is for app development again in 2018, but many of us aren’t sure what’s going on or why we should care. Sure, we know it’s something for app developers and they love it, but why do they love it? What exactly is it?
Kotlin is a programming and development language from JetBrains, which is the company behind the IntelliJ Java IDE (a developer suite of tools and applications that works together as Microsoft Office does) that Android Studio is based on. But Kotlin isn’t a programming language on its own; it’s a new way to write code that uses Java to run.
There are lots of features that make kotlin way more different and convenient than java.
- Kotlin uses aggressive type inference. That means it can tell what type of data a function is using based on the rest of the code and how it’s being used. This means developers don’t have to spend time declaring the type of expressions and values in their code unless they are doing something really outside the box. That saves a lot of time because declaring a data type can be tedious and the code has to be perfect.
- Kotlin lets developers define static objects and functions without needing to use a redundant class. A developer can define the objects and their functions all in one place, so it’s a lot easier to read and understand, which makes it easier to debug. And they don’t have to include code that shouldn’t be needed because it duplicates what they just typed. Java forces this because that’s how its syntax works. Kotlin is more relaxed and like writing code in C, and in this case, it’s easier and makes more sense.
- Kotlin’s syntax isn’t absurdly complex. Java’s syntax is. That’s why it takes years to be an expert Java developer — you need to include things like semi-colons and braces and brackets in exact places so the compiler (the tool that turns code into an app) knows what to do. Kotlin’s syntax uses the best ideas from programming languages that existed before it and writing code is simpler. This also means reading and understanding the code is easier and debugging it takes less time.
The three things above all have one thing in common, and it’s why developer love Kotlin so much — the code is more friendly. Writing the code is faster, more forgiving and just plain easier than it is in Java, and reading the code you or someone else has written makes more sense. It still looks like code, but not all code is equally complex, debugging seems a less tedious task in comparison to Java. In the end, you still get an application that can do almost anything a developer wish for but making it involved fewer hassles.
Kotlin takes much of those COMPLICATED things away. You still need Java installed on a device that runs apps written in Kotlin because it creates an app that runs just like it would if written in “regular” Java. But it’s a lot easier to write apps using it! Kotlin is a programming language that Android developers can use to build apps that are great while spending less time figuring out the tiresome parts and debugging test versions. You get great apps, and developers have an easier time writing them.
Some useful links
- Kotlinlang.org: The official Kotlin website. Includes everything from a guide to basic syntax to the Kotlin standard library reference.
- Kotlin Koans Online: A collection of exercises in an online IDE to help you learn the Kotlin syntax.
Kotlin on Android
- Get Started with Kotlin on Android: A short guide to start using Kotlin in Android Studio.
- Kotlin-Java Interop Guide: A set of rules for authoring public APIs interoperable in Java and Kotlin.
- Kotlin Style Guide: Google’s Android coding standards for source code in the Kotlin Programming Language.
- Sunflower: An end-to-end sample app that illustrates Android development best practices with Kotlin and Jetpack.
- Google I/O Android App: The 2018 version of the Google I/O app was completely rewritten in Kotlin, and it serves as another great end-to-end Kotlin sample app.
- Kotlin samples: A collection of Android code samples written in Kotlin.