Accessing values from an array using subscripts is a light and easy way to fetch list data. Kotlin brought uniformity in data access across regular arrays and Lists by allowing us to access data from a List using subscripts. But, what about our custom data models? Can they have subscripts if they mostly represent a […]
Changing line heights in Android using LineHeightSpan has this ugly side-effect where the cursor ends up being very tall, extending till the full line height instead of just the text height. I’ve decided to go to extreme lengths to fix this over the next few days. For science. pic.twitter.com/2tWLvDq1rz — Saket Narayan (@Saketme) November 24, […]
Custom getters and setters for fields in a class is not a new idea. We have been using them since our early days in programming. Kotlin, however, takes that concept to a more elegant level by allowing us to define getters and setters at the declaration site of our properties. The primary advantage of this […]
We recently shipped Data Saver Mode, a new feature on Instagram for Android that helps the app consume less mobile data. In this post, we’ll go over why we decided to work on this feature, our approach in developing it, the engineering implementation, and how people were impacted by it. The motivation behind building Data […]
Previously, we discussed how Kotlin’s type aliases could make our code more readable. However, if you remember, since type aliases don’t introduce new types, they don’t provide any type-safety. This week we will be exploring Kotlin’s experimental inline classes which have benefits that type aliases provide but go further than that. A little about inline […]
Models in Kotlin with data classes are already leaner and cleaner than their Java counterparts. Abstracting away all those getters, setters, toString() and copy() method with a single keyword makes our models reflect the only thing they should be concerned about — holding data. As I was exploring Swift for a project, I came across […]
For us lot, who strive to clean up and make our code look pretty, Kotlin has a nifty little feature. It’s called type aliasing, and we can harness the functionality with the keyword typealias. This week, we will be seeing where and how type aliasing makes sense and how to start using type aliases in […]
Jetpack Compose is an intriguing library but is not without concerns. The Jetpack Compose library provides the ability to create declarative and reactive UIs written in Kotlin for Android. It’s another attempt to avoid XML layout files by allowing the creation of layouts in a DSL-esque manner. The library borrows heavily from cross-platform application frameworks […]
Time calculations have always been a sensitive topic in most programming languages. Kotlin is no exception. If we have a function which accepts a time value to calculate a duration, it’s challenging to enforce a proper unit that the caller must follow. Starting from Kotlin 1.3.50, we can now make use of the Duration class […]
A concept about single focus server functions written in Kotlin. Recently I found the need to create a Server-less Function for a project and was disappointed in both the lack of Kotlin options and the tightly-coupled, framework-specific code necessary to implement one. This lead me to ponder about how a Server-less Function could be implemented […]