The title might sound weird at beginning since many modern libraries or tools are designed to make developers write less code via ways like code generation or reflection. Those libraries are great and convenient to use because we write less code. However in my experience sometimes developers become careless and misuse those libraries by calling them everywhere they could. Eventually the codebase becomes difficult to read and maintain. Here are some examples I have seen many times and would like to share with you.
In my previous post Kotlin “By” Class Delegation: Favor Composition Over Inheritance I covered using
by keyword for class delegations. You can easily reuse and compose existing concrete implementations in your code. In this post I will be going over using the same
by keyword for properties and how you can use them to create reusable code and reduce awkward boilerplate code. I will also include some Android specific samples with delegated properties.
Genymotion is the most popular replacement for Android emulator, but by default it does not come with Google play services and play store. You will have to follow this guide and manually install one or two zip files to install required files. But now with version 2.10 Genymotion adds a one-click installer to automate the process!
Writing custom views or view groups is quite common nowadays, but sometimes it can be really cumbersome. You have to write overloaded constructors so that they would work properly in layout editor, or you define and implement some interfaces so that you don’t have to copy and paste the same code in different subclasses. With Kotlin we can easily avoid those common pain points when writing custom views and still enjoy full interoperability with Android!