Post

I love Kotlin but please don't abuse its features. I regularly see code like in the first function when you can instead write a simple if statement: it's shorter, easier to read, and doesn't allocate an object! Thankfully both functions compile to the same assembly when R8 is turned on.

Note that even when R8 is on, the first function will be more expensive in interpreted mode. It's only after compilation to aarch64 by ART that it becomes fully optimized. If you don't have R8 on, well… ART still does wonders on the final code mind you (no branches, and a single call).

0 reposts7 likes

No replies yet.