Android Notes #1 —Easier code review with call argument names on your data class

Thomas Salandre
3 min readSep 26, 2018

This series of articles is a transcript of all the good inputs given on a daily basis by my fellow tech lead Nicolas Mouchel and other colleagues.

In my company, we have a strong code review process and there has always been an issue with readability when dealing with classes which have several arguments. We used to use a Builder Pattern on Java but there is a much better solution with Android Studio and Kotlin data class.

Problem

Let’s define a data class in Kotlin with several arguments, for instance

data class InboxThread (
val message: String,
val dateLastMessage: LocalDateTime,
val memberPhotoUrl: String?,
val memberNickname: String,
val isPremium : Boolean,
val isScam : Boolean,
val scamReason : ScamReason?,
val isAnonymized : Boolean,
val threadMessageType : ThreadMessageType,
val directionThread : ThreadMessageDirection,
val isOnline : Boolean,
val lastMessageRead : Boolean
)

Android Studio, in a very smart manner, will automatically help you find which argument you are filling by writting the argument in small and grey letters:

But unfortunately this is not the case when you are somewhere else. For instance on Gitlab it will look like this :

Not easy peasy to find out which argument it corresponds to…

Solution

So if you want the argument to always be displayed you can use the call arguments name option like this :

It will look in blue in Android Studio :

And be visible everywhere else, for example on Gitlab :

Why it this so important?

Without using the call arguments names, if one of my colleagues changes the order of two arguments (let say isPremium and isScam) nobody will see it because the signature of the code will be the same.

This can lead to terrible failures!!

With the use of call arguments name, you can change the order of any arguments of your data class without affecting the rest of the code :)

Great, isn’t it ?

--

--