Janusz Leidgens

Freelance Software engineer

Talk Title

Type Safety and clear error objects in Kotlin

Room

Hangouts

Date

04.07.2024

Time

11:10 > 20 min

Share

on Twitter

If you, like many Android developers, come from a Java background, Kotlin has improved the reliability of your code and your life writing it a lot. Just with the introduction of nullable types much has changed for the better in the Android world. But type safety is not only nullability many of you may have seen a method like this:

fun updateTimer(id: Int, minutes: Int, seconds: Int): Timer?

It looks perfectly fine on the first glance. I have written methods like this many times. With three parameters all being of the same type however there is no way for the compiler to help in making sure that everybody calls this method in the right way. The compiler will only check if the values are technically correct but it can not prevent users of the method to submit conceptually wrong values, for example milliseconds instead of seconds.

My talk will give an overview on how to make code more type safe through the use of existing classes and through adding more and more domain specific types. One example of these types are id classes that make sure you supply a valid timer id to the method above. I will also give an overview of the ways you can handle unsafe data both on a code and on an architecture level. This will help to protect your app from crashes, the next time the backend team promises that: “this field will always contain a valid value”. The last part of the talk will introduce you to the idea of railway oriented programming and show a way to make error cases more explicit and understandable.

Speaker Bio

Janusz develops for Android for nearly 15 years, working in agencies and startup product teams. 
In this time he led teams as a technical and also as people lead. He worked on green field projects and in long refactoring projects. 
Since 2022 he works as a freelance Android developer.

Menu