What is Kotlin and why should I care about it?
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?
To start with, you need to understand that Kotlin is only part of what Google is doing to make Android app development "better". I say better here because these tools do more than make it easier or faster, they allow developers to do more and build out better apps. Apps that work "better" look "better" and handle resources "better". Back to Kotlin — it may be only part of Google's developer toolkit, but it is the most important part because it does more than any other new feature to make apps and their development "better".
I love this video. I know a lot of us won't understand much of it (and I don't understand it all myself, no shaming here) but you can tell that the presenters— Chet Haase and Romain Guy — are genuinely excited to show the tools off and the developers in the audience are just as excited to hear about them. We also see how Google has doubled down on not just supporting Kotlin, but integrating it with extensions that will make building "better" apps even "better".
So what is Kotlin?
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.
Java is something you've probably heard about. It's a programming language that can build applications that run on almost any operating system on any hardware. It's powerful, meaning you can use Java to write programs that do a lot of different things like games or utilities or hardware control or anything else. It's also the programming language that almost every Android application is written in, as well as parts of Android itself like your home app or phone dialer app.
Kotlin can build apps that run on Java with a lot fewer headaches.
Java is also very cumbersome to code in. Because it's so powerful and is cross-platform (the device you're using to read this probably has a Java application framework and runtime installed) it's complicated. Java is a multi-paradigm programming language that supports object-oriented programming. You write code using objects (a variable or a function or almost any kind of data set), and you use classes to define the type and initial data inside an object. Oh, and you had to be sure to include the right libraries that let the classes define an object. See what I mean when I say complicated? And I'm even leaving out a huge chunk of information about how object-oriented programming works and just giving a basic overview.
Kotlin takes much of those cumbersome 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 hard parts and debugging test versions. You get great apps, and developers have an easier time writing them.
What makes Kotlin better?
Developers that I've talked to love a lot of things about Kotlin but there are three things it brings that everyone seems to mention.
-
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. In the end, you still get an application that can do almost anything a developer can dream of, but making it involved fewer headaches.
Is Java being phased out?
Nope! If anything, Java is being made stronger and better with the newest versions of Android and Android Studio.
I've heard Kotlin defined as "Java light". That's both a good and bad way to describe it, but it gets the message across — Kotlin is almost the same as Java, uses the Java machine in your device to run a finished app, but has less of a frustration factor. Kotlin needs Java to be installed on your phone or computer or whatever the future of devices brings to run. It's fully interoperable and you can even use Kotlin and Java at the same time in an application.
Kotlin also lets platform developers (think the people that "make" Android) add in support tools to make writing code even easier. We saw that at Google I/O 2018 when extensions for Kotlin were added, which act as a shortcut to write out all the code needed for something a developer will need to do over and over.
Rather than "Java Light" Kotlin is better described as "Java++" because it's a natural evolution of the language and can do the same things with less frustration.
Will the apps be better or look different?
Maybe, but because of the side-effects of using Kotlin and not the features of the language itself.
The programming language has very little to do with the way an app looks or how it works. It's simply how a developer tell's your phone to do something and then show you the result in some way. If a developer can spend less time writing the complicated code that makes your phone do that thing and tell you about it, they have more time to add better features or build a better design.
Developing any application involves several major steps. Writing the code is no more important than building a great design and user interface or making sure the app does something people will want it to do. Writing the code can take more time, though, and freeing up that time allows for the other phases to get better. Kotlin frees up a portion of the development time.
Where can I learn more about Kotlin or get started using it?
Visit JetBrains' Kotlin website for everything you need to get started. From there, you can get the basics and an overview of Kotlin on a more technical level. For Android development, visit these pages:
- Kotlin at the Android Developer pages
- Android Kotlin Extensions
- Kotlin Style Guide
- Kotlin Interoperability Guide
You can use Android Studio, Eclipse, IntelliJ IDEA or a standalone compiler to build Kotlin apps for Android or your web browser. There are even great tutorials to get you pointed in the right direction!
It's not difficult. There is a learning curve if you've never done any sort of development, but it's fun. Don't be afraid to try and learn as much as you can!
Update, May 11, 2018: This article has been completely rewritten to reflect changes made to Kotlin since it was added to Android in 2017.
0 Response to "You Can See More: Kotlin: Everything you need to know about Android's newest development language"
Post a Comment