Build, Design

What We Learned at KotlinConf 2019

Last month, I joined about 1,600 other participants at KotlinConf 2019, in Copenhagen. The two-day event showed that Kotlin is evolving fast as a programming language and as a community.

The language development started as a project of Jetbrains, the software development tool company. In a successful partnership with Google, Jetbrains’ Android Studio is the official development environment for Android apps and projects, and Kotlin has first-class support from Google’s Android tooling teams.

Being a modern language that also targets the Java Virtual Machine (JVM) ecosystem, Kotlin is a natural fit for business applications running on the server, and is becoming very attractive for people and organisations coming from a Java background. Given my interest in server-side programming and in the Kotlin language features, here is a summary of my favorite talks from KotlinConf 2019.

PSKotlinConf.13167_22ad

Putting Down the Golden Hammer, by Huyen Tue Dao

Kotlin comes with some nice features: type inference, extension functions, scope functions, operators for null safety (`?`, `!!` and `?:`), implicit single parameter for lambdas (the `it` value), and so on. As we learn Kotlin, we may overuse them.

Huyen, who currently works on Trello at Atlassian, showed some examples of where making things simple by writing explicit code looks better and more readable while still keeping the Kotlin idioms.

Coroutines Case Study: Cleaning Up an Async API, by Tom Hanley

You may have tried Goroutines in the Go programming language to trigger concurrent executions of functions. Now, you may be surprised (or not) that Kotlin also has its own implementation: Coroutines. Used together with Channels for communication between different Coroutines (sound  familiar?), robust concurrent programs can be built without shared variables and data races between threads.

This talk, by a senior software engineer at the software company Toast, showed how this approach was used to wrap an external third-party API that was based on listeners and shared memory.

Design of Kotlin Serialization, by Leonid Startsev

This talk, by a software developer at JetBrains’ Kotlin Libraries, was interesting not exactly because of the implementation details of serialisation strategies, but because it gave me a good overview of the plans for the platform. The speaker addressed a question that was in my mind: Why does Kotlin need yet another serialisation library?

While the JVM is well served by good projects—namely Jackson, GSON, and others—Kotlin would still benefit from a Kotlin-specific library to enable multi-platform compilation covering Kotlin/Native and Kotlin/JS projects.

Additionally, it was clear how the compiler development follows a modern modular structure, with a frontend part targeting the language itself and backends for different runtime targets.

Asynchronous Data Streams with Kotlin Flow, by Roman Elizarov

Elizarov is a team lead at JetBrains’ Kotlin Libraries and frequently gives talks about Flow, Coroutines, and concurrency. In this talk he described some use cases and compared Flow with similar libraries like RxJava, but for me the most interesting point came later when I was checking some more content from him and was introduced to the concept of structured concurrency. That’s where concurrency primitives, like Kotlin’s Coroutines, are always bound to a parent scope as opposed to unbound execution flows such as Go’s Goroutines.

Failure Is Not an Option: Error Handling Strategies for Kotlin Programs, by Nat Pryce and Duncan McGregor

A significant portion of developers don’t like checked exceptions— and I sympathise with them. This talk, by veteran developers Pryce and McGregor, shared a point of view where expected failures, like validations and networking issues, should be handled locally, without propagating exceptions up the stack.

On the flip side, for general unrecoverable errors like out-of-memory or programming errors, the speakers said, it should be fine—if not desirable—to interrupt the normal execution of the program with an exception.

I absorbed the content of this talk better after pairing it with this blog series from one of the authors about the same topic. A sealed class hierarchy, like `Success` and `Failure` extending `Result`, is used to carry the result of a computation that can fail and force both cases to be handled without changing the flow of the program with exceptions. After all, some functional structures feel nice with support of Kotlin idioms like sealed classes, inline functions, and extensions.

What’s New in Java 19: The End of Kotlin?, by Jake Wharton

After some long periods between releases, since version 9 Java has been rolling out new versions every six months. Jake, an Android engineer at Google and a well-known figure in the Java and Android community, tries to project the evolution of the Java language besides Kotlin for the next few years.

The comparisons are unavoidable. With language features side by side to the JVM bytecode level, his bet is that (spoiler alert) Kotlin will keep growing fast and strong.

The Power of Types, by Danny Freussler

You may have heard about primitive obsession in programming. Knowing it by the name or not, we all tend to abuse primitives data types. The use of string to define email addresses, URLs, or dates is just the tip of the iceberg, always followed by if-else statements for validation and exceptions handlers.

The talk by Freussler, an Android engineer at SoundCloud, presented good cases in Kotlin where more specific types—usually tiny classes—are defined to describe exactly what kind of data is expected. It has always been a dilemma, as tightly typed programs tend to have a larger number of type definitions which, initially, can be harder to read. But it pays off: the compiler will be your best friend, making sure your programs are correct.

Do It in Code (Not YAML)! Unlock the Power of Kotlin DSL for Kubernetes, by Fedor Korotkov

YAML is a nice format for declarative configuration files mapping inputs for Kubernetes APIs. However, the advantages may get blurry when browsing a directory with multiple huge config files. Indentation, string versus number formats, multiline strings for embedded text or commands can all lead to silly mistakes. Additionally, it’s hard to reuse the files between projects, and with a layer of if-elses and for-loops on top for templating, things become hard to follow.

The talk by Korotkov, an engineer at Cirrus Labs, presents a solution to handle Kubernetes manifest files via actual code that compiles. While it uses Kotlin’s type-safe builders to create a Kotlin DSL, the general idea of infrastructure configuration as, in fact, code that can be compiled is interesting regardless of the programming language.

 

Wrapping Up

In addition to my favorite KotlinConf talks, I feel I still need to mention one that came as a surprise bonus for me. I was very happy to be able to see a talk from Erik Meijer, contributor of many reactive and functional programming initiatives. Although his presentation about Gradient Descent optimisation was a bit off-topic, it was great to see him in person with all his personal touch: a sharp sense of humor and nice colourful shirts.

KotlinConf 2019 was a great event. The content showcased the different aspects of the language, the platform, and the community. With the partnership between JetBrains and Google, It seems Kotlin is already established as the first choice for development of Android apps. Following the adoption of Intellij IDE by the Java community, Kotlin keeps growing in preference for applications running in the JVM, for being modern and yet pragmatic and efficient.

It’s definitely worth keeping an eye on Kotlin.

Primary image by Eamonn Boyle, Instil Software

hiring.png

Comments
Leave your Comment