Learn Kotlin: Shortcuts

In this article:
Subscribe to our blog:

Learning Kotlin was something I thought about. Recently I decided to give it a try. And I’m so excited that I have!

If you are unfamiliar with Kotlin, it’s a newer programming language that has gained significant amounts of traction in recent years. And why not? It has a series of advantages, especially over Java, that makes it quite compelling.

Here’s a short selection:

  • It’s developed by an experienced software company, JetBrains.
  • It’s a first-class language for Android.
  • It’s influenced by JavaScalaGroovyC#GosuJavaScript, and Swift.
  • It’s interchangeable with Java.
  • High Order functions. These are functions that accept functions as parameters.
  • Null safety. Variables need to be nullable to able to be set to null.
  • Extension Functions. These allow you to extend an existing class, without inheriting from it.
  • Type inference for variable and property types
  • Data classes: These automatically have equals()hashCode()toString(), and copy() functions.

And these are just a small selection. If you want more, definitely check out this list from Android Authority.

However, if you’re still sitting on the fence regarding learning Kotlin, I thought I’d share a series of tips and resources with you, to get you off the fence and learning.

Resources

The Official Kotlin Site

The Official Kotlin Site

Like most languages, there is an official site for the language, at kotlinlang.org. There, you’ll find a wealth of information and helpful resources, whether you’re a beginner, intermediate, or more advanced Kotlin developer.

There’s Kotlin’s reference documentation, which steps you through from the absolute basics, including basic syntaxidioms, and coding convention, through the entire feature set of the language, such as classesobjectsgenericsnested classes, and lambdas.

There’s a range of tutorials that

  • Get you started using both IDEs and the command line
  • Show how to work with build tools
  • Show how to use Kotlin in a range of different environments, such as with AndroidJavaJavaScript, and Web Development.

Then there is a list of books, including Kotlin in action and Kotlin for Android Developers, and a host of other resources, including frameworks, libraries, editor and IDE plugins.

After having spent much time on KotlinLang, and performing numerous searches, I’ve yet to find a site that so offers such well organized and comprehensive information on Kotlin as this site does. Other sites, such as those created by individual developers, are great, but nothing tops the depth of information that you’ll find here.

My tip is to either pick one of the getting started guides in the tutorials section or work through the Overview and Getting Started sections in the Reference section. Then, build your knowledge progressively from there.

The Kotlin Slack Channel

Kotlin Slack Channel

The next best resource I’ve found is the Kotlin Slack channel. I begrudgingly accept that IRC doesn’t have the popularity or mindshare that Slack has achieved. And if I could, it’d be IRC all the way.

However, the people have spoken and the Slack channel it is. In the channel, you’ll find channels for discussions for:

  • Working with Android.
  • Getting started.
  • Server and JavaScript development.

Like all good communities, you’ll find helpful advice to questions that people have, links to exciting tidbits, recent happenings, libraries and packages, and a heap more.

The experience I’ve had there has been excellent. Even though I’m relatively new, the community’s been welcoming, knowledgeable, and responsive. I can’t say that for every community I’ve been a part of, or which I’ve attempted to interact.

A Twitter Search for Kotlin

A Twitter Search for Kotlin

While Twitter doesn’t have quite the reach and popularity that it once did, it can still rapidly yield significant results for technical topics. Just searching on “Kotlin” returns links to a plethora of information, which includes:

  • Kotlinconf17
  • Code style discussions
  • Tooling support, such as SpringGradle, and IntelliJ IDEA
  • Platform-specific discussions, such as for Android and iOS
  • Discussions about language features, such as coroutines
  • Accounts of leading Kotlin developers and influencers, such as Andrey Breslav, Kotlin’s lead language designer.

Tips

Now that we’ve worked through a series of top resources let’s look at a set of tips to help you get your Kotlin on.

Grab a (Free) Copy of IntelliJ IDEA Community

IntelliJ IDEA Community

While there are a range of IDEs that support Kotlin, such as Eclipse, none has as through support as IntelliJ IDEA, by Kotlin’s core development company, JetBrains.

I might seem biased, as I love using PhpStorm when writing PHP code, and in a way I am. However, even a small amount of googling will return results for IntelliJ than for any other editor or IDE.

There are two versions, Ultimate (commercial and not free) and Community (open-source, released under the Apache 2.0 license). Naturally, there are some differences between the two.

For just getting started, the community version has all the functionality that you will need, such as code analysisinsightsinspectionsintegrated version controlcode completion, and an absolute plethora of plugins.

However, those differences aside, it provides rich functionality, including:

  • Integrated tooling for rapidly bootstrapping new Kotlin projects using both Maven and Gradle, of which the latter I’m finding the preferable of the two.
  • Handles template project directory creation
  • Has integrated Gradle support, so that you can perform any task directly from the UI. You can drop to a terminal if you prefer that approach, as the projects provide gradlew and gradlew.bat, command-line utilities for running any Gradle task.

Do the Koans

Kotlin Koans

Let’s say that you’ve installed a copy of IntelliJ IDEA Community and created a basic project. Now what? Good question. Like any skill, to get better at it, you have to use it regularly, progressively learning every aspect of it.

You have to learn in an organized and focused manner. To help you do that, Kotlin offers Koans. Koans are:

A phrase, dialogue, or saying that a practitioner uses to break down the shell of his or her identity. The koan serves as a surgical tool used to cut into and then break through the mind of the practitioner.

They’re a way of breaking down and learning a skill, and they come in three forms:

1. Kotlin Online Koans
2. As plugins for IntelliJ and Android Studio
3. As a GitHub repository

The online version, which you can see above, offers a list of 42, covering the core language features, starting with the most basic, simple functions. Using them, you can learn in an organized fashion, progressively improving your skills.

That way, you have a clear path from beginner to advanced, you can see how much you’ve learned and how far you’ve come, and you don’t have to search for what to learn next endlessly.

Port an Existing Application

Assuming that you’ve worked through several — or all — of the Koans, and you’re feeling comfortable with your Kotlin knowledge (as well as of its idioms), it’s time to build a meaningful application; something other than the typical Hello World example.

The trouble is, everyone’s needs are different. So what kind of application should you create?
I offer advice from a programming mentor of mine, John Sonmez, when he quoted Douglas Hofstadter:

The only way that we can learn new information is that it’s an analogy to something else.

He suggests that when you port an existing application (preferably one that you’ve created), you learn so much quicker as:

  • You don’t need to think about what to develop.
  • You can learn the new language more rapidly, as you’re learning it through analogies to an existing one.
  • You can relate the language to what you already know and build on that existing foundation

Ideally, I’d suggest that the application which you port is smaller rather than bigger. That way you can gain a sense of success and satisfaction quicker.

However, the application needs to be more than “hello world”, so that you can cover a sufficiently broad cross-section of the new language, and not just grab the low-hanging fruit.

Learn from Existing Projects and Other Developers

The last way that I suggest that you learn Kotlin, is something not specific to Kotlin, but applicable to any software language, it’s by reading through code of existing projects and by learning from other developers. I can’t recommend this approach highly enough!

If there’s one way that propelled my knowledge of a language, it was by working with developers (often far) more experienced than I was.

By seeing how they approached and solved problems, the way that they wrote code, the evolution of their code over time, and asking them questions, I learned far more rapidly than learning on my own.

I’m not going to go into significant depth here, suffice to say that these two approaches are veritable treasure troves of knowledge that you never want to pass up.

Links

Time for one last tip, a set of links to various blog posts that have helped me no end as I’ve been learning.

  • Why Kotlin is my next programming language. This post provides a thorough and detailed analysis of why developer Mike Hearn made the move from Java to Kotlin. Despite being written back in mid-2015, the reasoning is still very valid. He discusses why Kotlin’s a good language, as it compiles to JVM bytecode and JavaScript, interchangeable with Java, can use existing Java frameworks and libraries, and has strong commercial support; if you’re keen to get a deep-dive introduction, read this first!
  • Why You Should Totally Switch to Kotlin. Written by Magnus Vinther, provides seventeen convincing reasons for switching to Kotlin; including IDE supportbetter LambdasRangesDestructuring Declarationsoperating overloading, and the When Expression. Afterward, he provides a series of links to other blog posts, some of which I’ve included here, that build on what he started.
  • Why I Abandoned Java in Favour of Kotlin. Written by Jan Vladimir Mostert, this post was an amusing read as Jan openly states that he fell in love with Java, yet felt that he had to move on and that Kotlin was where he had to go. Given that strong affiliation with Java, he presents a compelling set of reasons for doing so.
  • 10 Cool Things About Kotlin. As the name implies, this is a list post about ten excellent features of Kotlin. A lot of the points are covered in the other links provided. However, what’s nice about this post, is that it allows you to dip your toe in the water, without getting overwhelmed in too much detail. So if you’re short on time, or want to know what the fuss is about quickly, start here.
  • Swift is Like Kotlin and From Java to Kotlin. These two sites provide a concise and well laid-out comparison of a range of Kotlin’s language features, and how they would be written in either Swift or Java.

In Closing

Those are my shortcuts for learning Kotlin. I’m not as experienced as other Kotlin developers, but I see that as an advantage, not a hindrance.

I hope that my relatively fresh eyes and enthusiasm have given you a substantial insight into why Kotlin must be on your list of languages to learn.

If you know of other reasons or want to share your experience coming from another language, I’d love to hear it in the comments and to have a discussion with you. So don’t be shy, share your knowledge!

Oh, one last thing, if you’re keen to review the quality of your Kotlin code, Codacy has your back, as they have Kotlin in their list of supported languages. Sign up, login, add your project, and get a handle on its quality.


About Codacy

Codacy is used by thousands of developers to analyze billions of lines of code every day!

Getting started is easy – and free! Just use your  GitHub, Bitbucket or Google account to sign up.

GET STARTED

RELATED
BLOG POSTS

Atlassian Connect for Bitbucket: New Codacy Integration
A few weeks ago the Bitbucket team approached us to become one of the first Bitbucket integrator on Atlassian Connect. Today we are happy to announce...
Why Open Source Technology
We love open source technology here at Codacy. Open source allows programs to be publicly accessible so that people can modify and share creating a...
Introducing Codacy for PHP projects and easier file ignore
Starting today, you can put Codacy to work on your PHP projects. We’re also putting into production an interface for you to easily ignore files and...

Automate code
reviews on your commits and pull request

Group 13