According to the latest Octoverse report by Github, Kotlin has seen 2.6x growth in contributions as of September 2018 and is already becoming the go-to programming language for Android development. Understand what has made it inevitable.
Kotlin got big when it acquired the backing from the search engine behemoth at Google I/O 2017. It is now the official programming language for Android development besides Java and C++ and #4 most loved languages in the tech world. (Source: StackOverflow)
As one of the most modern, statically-typed, open-source programming languages, Kotlin can run seamlessly on Java Virtual Machine (JVM). It has similarity with Java, JavaScript and C++. So as a developer, if you know these languages, you can get started with Kotlin in a couple of hours.
Initially, when Kotlin was rolled out, most experienced developers started giving it a try. However, since it has been made the official Android language, more students and developers are moving towards Kotlin to build apps.
According to a RedMonk Report -
Around 80% of Developers are using Kotlin to build Android apps. About 31% use it for backend/server-side applications, while another 31% said they used it for SDK/libraries.
JetBrains — The ‘Brain’ behind Kotlin
Kotlin has been around 2010. JetBrains developed it to solve their own, internal development & productivity challenges. They are a software development company, and their core area of expertise is — IDEs. The basis of an IDE is a programming language. The first version of Kotlin came out in early 2016. And, since then Kotlin has been witnessing exponential growth.
Why was Kotlin built?
Almost 70% of JetBrain’s products are built with Java. Slowly and gradually the company was getting tired with the old fashioned ways of writing code. With Java, even a fundamental thing like “Hello World” would require any developer to write three lines of code whereas modern languages can do this in about three words.
This means more repetitive work. What JetBrains needed was a new language compatible with Java that would translate to adding new features to existing apps without rewriting things from scratch, and that is less code. They tried Scala, but it was not as fast as they wanted it to be.
That’s how they built Kotlin.
Developers are gravitating towards Kotlin because it’s making them happier.
If you are into Project Management and Team Communication, chances are you use ‘Basecamp’. The company has been one of the earliest adopters of Kotlin.
A third of the Android app’s code was Kotlin-based back in May 2016 (it’s now 100% Kotlin). The code is better, users are happier (the ultimate goal for any developer) and so are the programmers. What’s going on, you might ask?
Dan Kim, the android guy at BaseCamp, found himself uttering ‘holy-shit’ quite a few times when he started writing code using Kotlin.
A popup adapter was his first Kotlin class. He completed it in 86 lines. The code was concise, readable and more importantly, he had fun writing it. Less was, indeed, More.
Next, while converting an existing helper class, he just reduced 94 lines of code.
He had just fallen in love with a programming language and as a developer myself, I can tell you how hard it is to love a language.
Here are some of his favourite Kotlin features which they regularly use at Basecamp.
Interestingly, he also shares how Kotlin has made him a happy programmer.
As developers, we want to use frameworks/languages to come up with creative solutions to business problems than just cranking up some boilerplate code.
Here’s how he puts it -
Writing code that’s concise, clear, and expressive makes me happy. Focusing on creative solutions to business problems, not boilerplate and ceremony, makes me happy. Feeling an intense motivation to learn, which was missing in the Java days, makes me happy.
And that’s super important. Because being happy isn’t just good for the soul. It’s great for your programming skills too.
The more capable and friendly your language is, the happier you are. The happier you are, the better code choices you make. The better code choices you make, the better habits you build. And the better habits you build, the better programmer you become!
This is exactly what’s happened with Kotlin and me over the past year. And I’m a better programmer because of it.
Read more about his thoughts on Kotlin here.
Christina Lee is an Android Engineer, and she was one of the first, few people at Pinterest to try Kotlin for the video pin feature. She says, “working with it will bring a smile on your face.”
Any organization/company that has been using Java for years can quickly find itself in a quagmire — whether to continue using Java or try Kotlin? Because Java can do everything that Kotlin can. Millions of apps, today, are still baked with Java and continue to function well.
The difference is that Kotlin speeds up the development. How?
With more straightforward and easier to read code. No more using that boilerplate code.
Kotlin sure has a more beautiful syntax, but it’s not about the features and functionalities any more. These features ensure that you have a more productive development environment.
The Kotlin-based feature was introduced to approx. 150M users a month.
Similar to Dan’s views, Christina opines that —
Kotlin is not a radical departure from Java, as both produce bytecode for the JVM. But what makes it so nice to work with is that it is essentially a version of Java where best programming practices have been built into the language, so it is much easier to do the right thing than it is to do the wrong thing. This allows a developer to code with speed and confidence and removes much of the rote work that had been required while using Java.
Because coding, like writing, is an expressive art form, having a tool like this that allows you to express your thoughts clearly, quickly, and accurately is a satisfying phenomenon and one worth getting excited about. When you combine this with the industry-leading tooling and interoperability of the language and the thorough and thoughtful language leadership displayed by the team at JetBrains, it was difficult not to fall in love with it.
Listen to her thoughts here
Caviar app, the on-demand food delivery app owned by Square is also 100% Kotlin-based.
When Valeriy Ovechkin joined the Caviar team as a software engineer, the app was 100% Java. He started experimenting with Kotlin as a ‘passion project’ and pitched to the ‘Square’ team that it will make the development faster.
When the existing features were rewritten in Kotlin, there was no significant impact on the end-users. But for developers, it was a game-changer.
With Java, coding can be slow, and results can be clunky at times.
Valeriy, gradually, started writing the new features in Kotlin because it’s easier to learn and makes the whole experience delightful. Writing fewer lines of code is what makes developers stick around.
“What is interesting with Kotlin is basically it leverages the existing skills of Java developers and finds the right tradeoffs to provide new features and provide things that make Java developers more efficient without going too far,” — Pivotal engineer Sébastien Deleuze
According to Ovechkin, the code (for Caviar’s Android version) is smaller by 15–25%. That’s because — Kotlin allows you to write concise, smaller amounts of code which results in easier management. Developers can focus on more significant problems than routine tasks.
From Uber to Atlassian, biggies across the globe are using Kotlin to power their apps, back-end etc. Its usage will only grow in 2019.
Why a 100% Kotlin-based Android App is the best bet for your business?
- Low Risk — Start small by rewriting an existing feature of your app and see how it goes. Have it as a side project and see how your users react. This means your entire product does not need to invest much in the beginning. It is possible because Kotlin classes export a Java API which is similar to Java code.
- Active support community — Kotlin is backed by Google and has become the official language for developing Android apps. There are tons of resources, talks and community help available to solve your queries regarding anything you feel stuck at.
- Open source — You don’t need to purchase Kotlin. It’s freely available. If you know Java and C++, you can quickly develop your MVP and start testing your idea before investing full-fledged. You can crank out the best MVP within limited time and budget.
- Efficient teams — When your team has to code less, it becomes more productive. Use their time efficiently to work on bigger, better issues than just code usual, routine stuff. It saves their time. It helps them work faster and better.
- Easy on maintenance — Less code, less maintenance, fewer nightmares. Additionally, there are tons of IDEs available for your developers, let them choose the SDK/toolkit of their liking.
- Compatible with previous versions — Ask any Android developer, and you’ll know the pain point I am talking about. Kotlin is 100% backwards compatible.
- No more memory leaks — The last thing you would want on your app is impaired performance. Kotlin helps avoid memory leaks.
- Interoperability with Java — Old projects working on Java? Never mind. Continue working on them with Kotlin.
Ending Notes
We strongly suggest you start using Kotlin for your android apps. At Solutelabs, we too have shifted from Java to Kotlin for building products for our clients, and they have been more than happy with the result. Start taking small steps today to reap big benefits tomorrow.
Cheers!
Top comments (3)
Very nice writeup. Thanks for putting it together!
Just want to add a few comments since this is very top of mind for me.
Kotlin Multiplatform also allows sharing code on iOS, Web (JS, Wasm) and many others via LLVM.
Kotlin and Swift are also very similar, though, under the hood, they start to diverge. Better Kotlin <> Swift interop is ongoing with experimental generics support being the latest addition.
Both Square and Touchlab have been Kotlin fans for a long time which is why we were so excited to start working together.
Google I/O 2017 was definitely huge because Touchlab has had many conversations over the past couple years and brought on a few clients that have 100% Kotlin as a goal for Android and we've seen more and more chatter about Kotlin on the server and, of course, KMP for iOS too.
I love that you point out these benefits and risks. In the end, it's always a decision that needs to be made based on context and pointing these out is important for decision making. In my lightning talk at Lead Dev NY 2019, The Future of Cross-Platform is Native, I point out similar things, though from the perspective of understanding benefits/risks of cross-platform/multi-platform solutions.
I saw your talk and I felt it was great!
But given that Google is now backing Flutter more than ever and now officially allowing developers to create Web and Desktop apps (Even Android Auto and Raspberry pi) - do you still think KMP is the way to go forward?
Also, how do you see the synergy of Flutter with KMP going ahead in the future?
Is it wise to use both in an app with Flutter looking at UI and Kotlin on the business logic?
Thanks, glad you liked it. You'll remember from the talk I believe strongly in apps being "native to users" meaning it meets the user's expectations of the platform -- a Mac app looks/feels like a Mac app, an Android app looks/feels like an Android app, etc. Some examples:
Even with Google putting more marketing and engineering behind Flutter, I don't believe they will put enough effort into playing catchup with iOS guidelines and, in many cases, recreating native widgets is more effort than its worth (even for Google with a ton of cash to throw around).
At this point, I don't see much chance of a synergy between Flutter and KMP. It would be interesting to use Flutter as the UI layer for apps which shared UI makes sense and share business logic with KMP but Flutter's platform channels makes that seem like it won't be a nice experience.
From the user side
For apps where a solid user experience taking into account platform differences in UI, sensors, OS-level integrations, and/or Google/Apple-provided services, KMP is the way to go. And I think that is most apps that reach a certain scale.
Games are a completely different story which I'm not very familiar with. But, at least sharing UI and not caring about platform guidelines are expected. There are many 2d game engines around and Flutter is probably not a better one.
From the business side
See above because a business should be customer-first.
If you have an existing app (or portfolio of apps), KMP is the lowest risk -- continue to use first class langauges Kotlin/Java and Swift/ObjC, continue to use first-class tools Android Studio and Xcode, continue to support existing apps (Flutter is still a pain to integrate with others), start sharing business logic immediately (SQLDelight, Ktor, etc), don't worry about Dart or Flutter changing or shutting down, don't worry about losing investments you've already made.
If you are starting from scratch, it may make sense to start with Flutter for rapid development/experimentation/prototyping then move to native apps via KMP for production. Similar to how many companies had diminishing returns to React Native and have since gone back to fully native (they should be using KMP 📢).
Also
Something else that worries me is Dart doesn't have any plans to support Wasm, and doesn't work well with existing web apps, either. It is a capital 'B' big decision on mobile and web, whereas KMP is a small decision that you can iterate on to be bigger as you see fit.