Android Kotlin Style Guide

The Android Kotlin Style Guide is out, hooray! Their certain topics within the style guide for Kotlin that I believe are the best of the bunch and are a great starting point when converting over to this style guide.

If Statement

If statements need something to separate between the if statement and the other code. Look at the difference between the two if statements.

If you don’t believe me look at this code as well:

You probably have to look at the code for a few seconds to see theirs a tab indicating the if statement. The code should be easy to read at a glance, and this one needs a double take because of theirs no separation. Within the style guide, we should always have curly braces within if statements.

Variable Assignment If Statement

When assigning variables from an if statement we should always have curly braces as well.

Having curly braces should be mandatory. Without the curly braces, you can’t distinguish between the if statement and the actual code.

Try Cache

When we have a try cache with the cache empty their are certain things that need to be in place.

A try cache should look like this if the catch is empty.

Not this:

Leave a Reply

Your email address will not be published. Required fields are marked *