So how do you Kotlin?
Guest Post by Mike Gouline, Organiser at Sydney Kotlin User Group
You’ve likely heard about Kotlin at least somewhere by now. Perhaps, as the second most loved (and fourth most wanted) language in Stack Overflow’s Developer Survey 2018. Or maybe in the ‘Trial’ layer of ThoughtWorks’ Technology Radar 2017. If you’re in the mobile community, you definitely heard last year’s announcement at Google I/O that cemented Kotlin as an official language for Android development alongside Java. Some of you were even lucky enough to see JetBrains’ own Svetlana Isakova when she visited the Australian shores with her You Can Do Better With Kotlin talk, as part of YOW! Connected 2017 and YOW! Nights.
Whichever way you look at it, Kotlin can no longer be dismissed as a novelty language that bored Java developers like to give talks about at their local meetups. Far from it. It’s a mature production-ready multi-purpose programming language developed by the likes of Andrey Breslav, who are no strangers to either language design or Java. It’s also backed by JetBrains, a name familiar to many for their developer tools.
Here’s the question though: how do you learn Kotlin and start using it in your daily development? Hopefully, the rest of this article can help answer that and send you on your way.
Getting to a point where you understand the syntax shouldn’t take you long, especially if you’re somewhat familiar with Java. It’s an oversimplification, but the differences boil down to variable types and method return types following their names (instead of preceding), methods being called functions, variable declarations not requiring types (use
var instead) and other easy-to-spot changes that you’ll learn to love.
In fact, if you’re a Java developer, one handy way of picking up the syntax is just opening your existing Java code in IntelliJ IDEA (don’t worry, there’s a free Community edition that supports Kotlin) and clicking “Convert Java File to Kotlin File”. While this shouldn’t be used to bulk convert your whole codebase to Kotlin, it produces code that’s good enough to see the differences between your Java code and the equivalent Kotlin code.
Coming from a different background shouldn’t be much more difficult either, you’ll find that Kotlin shares many features, and sometimes even syntax, with other modern languages like Swift, Scala and C#. Going through the tutorials, your initial fear of the unknown will quickly be replaced by the realisation of how much you already know.
Uses and possibilities
Now that you’ve covered the basics, before you start writing code, think about what you want to use Kotlin for.
It’s a common misconception that Kotlin is primarily for Android development. Full interoperability with Java and the prospect of not having to write any more Java 7 are the primary reasons why the Android community quickly embraced it, but it’s just as useful for anything else that you can run on the JVM: web services, desktop applications, and anything else you can imagine.
In fact, Kotlin is not even limited to the JVM: Kotlin/Native is a promising initiative to allow it to run natively on all the major desktop, server and mobile operating systems. While it’s still in development, it already works and you can play around with some sample code or build your own. Have a look at the Spinner app presented at KotlinConf 2017 to demonstrate the capabilities of the Kotlin/Native software stack.
There are many possibilities and the best way to learn is, as always, by messing around with some sample code, and perhaps by setting yourself a superficial goal and trying to solve it with Kotlin.
Once you’ve gone through all the tutorials and “Getting started” guides, you may be wondering what the next learning steps are. Here’s the Cook’s tour of the reading, listening and watching materials that you may be interested in.
For those of you who like books, Kotlin in Action (D. Jemerov, S. Isakova; Manning, 2017) is a must-read to cover all the high-level concepts and the necessary details. Many other books are also available on specific topics, such as Android and web development, functional programming, and microservices, in the Books section of the website.
Reading articles and blog posts is another good way to keep up to date. To find relevant ones, it helps to subscribe to Kotlin and Kotlin Weekly on Twitter. The former reports on all the official news from JetBrains, such as new releases, features and announcements, while the latter is a weekly digest of the most popular articles and posts about Kotlin from the community.
If you prefer audiovisual stimulation to reading, you should check out the Talking Kotlinpodcast hosted by Hadi Hariri, where he talks to various interesting people who use Kotlin for their daily work. Of course, nothing beats randomly trolling YouTube for Kotlin videos, but a great place to start is the playlist from last year’s KotlinConf on JetBrainsTV.
Watching videos from the comfort of your home is well and good, but if you’re really interested in Kotlin, it’s always a good idea to attend a community event at some stage. Be it KotlinConf (next one is in October 2018 in Amsterdam) or a local meetup, you’ll meet other Kotliners and learn a lot. For those located in Sydney, Brisbane and Wellington, you’re in luck, there are Sydney Kotlin User Group (disclaimer: I organise this one), Brisbane Kotlin User Group and Wellington.kt. Otherwise, you can check if there’s one near you here. If you can’t find one within a reasonable commute, it might be worth checking your local Java, JVM, Android and similar meetups, you’ll notice that people often discuss Kotlin there, be it a themed night or just an occasional talk covering a Kotlin-related topic.
Hopefully, this article was a helpful starting point for your Kotlin journey and happy programming!