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ย Java,ย Scala,ย Groovy,ย C#,ย Gosu,ย JavaScript, 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
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 syntax,ย idioms, andย coding convention, through the entire feature set of the language, such asย classes,ย objects,ย generics,ย nested 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ย Android,ย Java,ย JavaScript, 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
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
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ย Spring,ย Gradle, 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
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 analysis,ย insights,ย inspections,ย integrated version control,ย code 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
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 support,ย better Lambdas,ย Ranges,ย Destructuring Declarations,ย operating 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.