Shortcuts to Learning Kotlin

Kotlin is a language I thought about using for some time, yet it wasn’t until recently that I decided to give it a try. And I’m so excited that I have!

If you’ve not heard of Kotlin, it’s a language that, while newer than most, 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

imageThe 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

imageThe 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

imageA 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

imageIntelliJ 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

imageKotlin 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.

Source : https://blog.codacy.com/shortcuts-to-learning-kotlin-a2d3af535c80

Related Posts

MNK \S4'=Q| K_4.7گc"7LQ0~lWjrRkh-i RZ9gs2[P8S!1M&*zW&HoPy{ J^>Ј}jrG0YQ