Whether you’re building applications for a start-up or a major corporation, you’re always building for multiple platforms. So how can you reduce complexity to build more maintainable products faster? You can take Jan Mostert’s advice and use a single language for all your business logic. He showed us how in his recent Tech Talk, and in this blog post he explains why Kotlin is a great choice for business applications.

Digging through different platforms and programming languages trying to find the best fit for a new project, I was surprised to see how many projects are trying to solve the multiplatform problem – and how close many of them are getting.
JavaScript has NodeJS on the backend, and until recently it was only event-driven and single-threaded. Recently it got worker threads to take care of CPU-heavy work.
The web is naturally a great fit for JavaScript. For desktop, you have Electron, if you don't mind shipping a full browser with your application. And for mobile, then PhoneGap, Cordova and Ionic might cover you if you don’t mind running in WebView. But I’m not a fan of the sluggish non-native feel of the applications. ReactNative gets much closer to a native feel. Since type safety is important for large commercial projects, maybe TypeScript is a better choice for full-stack JavaScript.

Adventure

Dart2 ticks all the boxes for a great language. It even has null-safety since 2.12. For mobile, web and desktop, you’re covered by Flutter. But server-side, you’ll unfortunately need to rely on projects that have been abandoned or that have been forked, with only a single maintainer, which is a high-risk choice for enterprise applications. If you like the adventure, however, Dart has Isolates which in a way serves a similar purpose to Web Workers, providing multithreading in a single-threaded environment.
AngularDart used to be the flagship product for Dart, but it’s been moved into maintenance mode since May 2021. Hopefully, the whole stack won’t end up on the killedbygoogle.com graveyard like so many other Google products.

Breath of fresh air

Java has stood the test of time as a server-side language with many mature frameworks to choose from. Personally, I like VertX when working on new Java projects.
For desktop applications, JavaFX is still around, although it’s not my favourite to work with. You have GWT for web applications and I'm reading J2CL might even be a breath of fresh air in the Java-to-JavaScript transpilers. For mobile, Java is still supported on Android. I'm not sure what the non-commercial options for iOS are though.
And C#? If you don't mind the bizarre uppercase function names and a level of Microsoft lock-in, then it too seems to tick many of the boxes. C# is mature, has been around on the server for ages, has options for mobile, desktop and web and can even do WebGL via Unity.

Fun-factor

In 2016, Kotlin emerged from the JetBrains factory after being under development for roughly half a decade. The language is Java-like, prides itself in being null-safe (effectively eliminating the ‘billion-dollar mistake’) and incorporating all the Java-best-practices right at the core of the language. The language also copies working concepts from other languages and it does so in an elegant manner.
I’ve been using Kotlin since 2016 and have delivered several dozen large backend projects using only Kotlin and few small libraries. Java teams that I introduced to Kotlin picked up the language in a couple weeks and had real fun using it.
Since KotlinJS went into alpha in 2017, I’ve been messing around with pre-release alphas. Although initially still a little rough around the edges, by 2019, when I started using it for production purposes, it felt much more polished. What a pleasure to write a server and web application in a single language; one that happens to be a great language to work in too!
In the same year, Google announced their love for the Kotlin language and made it the preferred language for Android development. When Kotlin Multiplatform Mobile emerged, things went fast. People started sharing what amazing things they’d built using alpha builds and raved about how they got to share business logic between backend, mobile and web platforms. Since the release of the new Kotlin IR compiler, a lot of things have matured.

Power

If you’re building server applications, then Kotlin is a solid choice. It’s also a great choice for web and mobile. Since Kotlin interops with other languages, it’s easy enough to re-use it with existing Java libraries on the server, JavaScript/TypeScript libraries on the web and Objective-C/Swift-libraries on iOS. For desktop (Linux, Windows and MacOS), you'll need to compile to native and interop with C-libraries.
In short, the power of Kotlin lies in how one language, one standard library, one concurrency framework, one serialization framework, many other Kotlin libraries and of course your own business logic just runs on multiple platforms. You write code once and deploy it everywhere.

Tech Talk: Sharing business logic between multiple platforms with Kotlin

Sharing code between multiple platforms? In this talk Jan discusses the available options, what makes Kotlin stand out and finally gives a short demo showing a server, desktop and web application all sharing some of the same code.

Watch the recording of Jan's Tech Talk here!

About Jan Mostert

Jan advises Capgemini clients on everything that has to do with ‘full stack’. He’s been programming since he was 15, and has a BEngSci degree from the University of Stellenbosch in South Africa.
job alert

Receive the latest vacancies