Adetunji Dahunsi

90 days of Kotlin

Change; as constant as the seasons. Photo by Chris Lawton on Unsplash

TJ Dahunsi

Jul 08 2019 · 3 min read

Categories:
android
kotlin

Old habits die hard. We’re creatures of habit, and provided there’s no stimuli that causes us to change and evolve, we’ll all very likely stay static. After all the more you repeat something, the better you get at it, and there’s little to be gained from change for change’s sake save for a new perspective, which can be rather varied in its returns.

I’ve been an Android Developer for a little over 5 years now, and I love Java. Quite a bit actually; its APIs for common data structures, it’s explicitness and the way it makes it easy to read someone else’s code, it’s OOO approach and how it lends to easy encapsulation and delegation to class instances, it’s recent adoption of a pseudo functional paradigm with functional interfaces and single abstract methods… the list goes on. Not only does it offer all this, but it does so while being backwards compatible with previous versions of the language, type erasure being one of the more fascinating things in the language to me. With all these and lots more, it’s not surprising Java and subsequently the JVM, is the thriving ecosystem it is today. I’ve spent a considerable amount of time learning about the language and it’s design decisions and they all seem extremely justifiable to me.

In 2017 however, my world was rocked a bit. Kotlin was announced as an officially supported language on Android at Google IO, and boy was there hype. I was miffed, why would Google divert so many resources to letting developers do the same thing a slightly different and unoptimized way? Unimpressed, I assumed it’d be a fad that’ll pass, besides Java wasn’t going anywhere.

Then Google IO 2018 rolled around, and Kotlin even had more hype, support, and backing than ever before. There were dedicated Kotlin libraries that did the same thing as Java libraries in a more “idiomatic” way. Mockk for mocking, Koin for dependency injection, and there was a huge plea for a Kotlin specific variant of the Reactive Streams specification. I thought the world had gone mad, even more so, I was upset at myself for not getting caught in the hype and began to feel quite a bit left behind. In other words, there had been stimuli, and the wheels of change had began to turn.

I couldn’t bring myself to use Kotlin in any of my existing personal projects, because of the risk it entailed. I needed a greenfield project, or to be in an environment where I had no choice but to use Kotlin. Lacking the creative inspiration to start a new project, I decided I may as well look for a job that had a Kotlin codebase where I’d have no choice but to use it.

In April of 2019, I started that job at GameChanger Media. It’s been almost 90 days since, and like so many other developers before me, I’m a convert.

I didn’t realize my conversion at first, a couple small commits at work here and there introduced me to some of the language features first hand. I didn’t think much of extension methods, but after being introduced to the concept of receivers and seeing their use in the standard library functions of run, let, apply, also, with and so on, my mind was blown. That right there was my Eureka moment.

That combined with the ease of creating function literals, expression syntax for methods, lazy delegation, late init variables, smart compiler casting… it all just made for a lovelier developer experience, and by a long shot. It wasn’t just a nice to have, it was a huge step forward in the way you could write and architect projects. I’ve since converted 2 personal projects to Kotlin, one an app on the Play Store with over 10,000 downloads, and the other a Home Automation project with zero regrets and plan to write about it soon.

Do I still love Java? Yes, but more in a legacy way now. Without it, there’d be no Kotlin, but Kotlin improves on in it so many ways that really it is night and day between the two. It’d also be non trivial to bring those same Kotlin features to Java in a backwards compatible way. It only took 90 days, but I wholly prefer Kotlin to Java. Couldn’t be a second earlier either, Google IO 2019 was a couple months ago… unsurprisingly, Google is going Kotlin first with Android now, I’m just glad I caught the train.