Since Android Studio 3, all my new projects are in pure Kotlin! I make sure I am somehow able to use Kotlin even if it involves explaining to the client, why they would rather want to have their app in Kotlin than in Java. One of the reasons why the clients don’t want to use Kotlin is because AS 3 is not a stable build right now. By the way, there is a Kotlin support plugin for AS 2, which can be used in place. Other reasons are vague like I’d rather have Java, it is standard, native apps are in Java, stuff that I can not and do not want to argue with.

I started learning Kotlin just as a fun hobby back when Google announced official support. I wanted to know what was all the hype about. I so wish I had started sooner.

You have to try Kotlin and if you haven’t already, you are missing out on a lot of great things. Some of the major reasons why I’d rather stick to Kotlin, in order of priority:

1. No null checks anymore

Kotlin programming language aims at eliminating the perils of null references from code, which is often called The Billion Dollar Mistake. All those if(x != null) and try catch blocks gone! And so many null pointer exceptions also gone! Who does not want that? Kotlin addresses null exceptions at compile time which automatically handles all the NPE’s that used to occur at compile time.

2. Extension functions

This is by far the coolest feature. You can add functions to a class, without actually modifying the class. Wow! These extension functions can be used like regular class methods and they are statically resolved. Again wow!

3. Type Casts

It’s already reduces code considerably and upon that is the is and the as keywords. It’s like you are writing English!

4. Lambdas and inline functions

Combined together lambdas and inline functions make the code a lot smaller and coding that a lot easier and simple. Although if you are used to Java syntax like me, it takes a little while to get the hang of these, especially when reading someone else’s code. But these are somethings that you would always want to use once you learn how to use them.

5. Have you met String templates

I mean seriously, imagine all the lines of code that went into computing values and then converting and putting into the final string, it all goes in that one line of string declaration, that is all seriously

6. The var and the val and the lateinit

Make variable mutable or non-mutable with var and val and if your variable is initialized later and you do not want to initialize it in declaration then just add a lateinit. Super convenient.

7. A class with 4 variables is so small in Kotlin

All the getters and setters are gone, no need for that boilerplate code anymore.

8. It’s wants you to write less code

When you are writing a block of code it is way shorter and simpler in Kotlin. Kotlin compiler can understand from the code and write the remaining code. For example, it can infer types in variable declarations. This increases productivity and saves time. A lot of keywords like extends are replaced by just a single character: in this case in Kotlin.

9. No more finding views by ids

In this you can directly address views by their ids, no need of the lengthy findViewById or for that matter Butterknife.

10. No semicolons ;

I love the no semicolon thing in python and now I don’t have to use them for every statement when building android apps. Such a time saver.

11. High Order functions

If you like to use RxJava and love the high order functions that fit perfectly with Kotlin.

12. Kotlin saves so much time

From the smart casts to the type inference and the considerably fewer amount crashes and of course how writing the same code in Java takes a lot more time, it is so much less effort with Kotlin.

13. It makes Android development more fun

If you search the web, you’ll find tons of ways in which Java’s pain points are solved by Kotlin and how these features aim to make Android development more fun. It helps you write more expressive and effective code with fewer bugs.

Any doubts? Leave comments. Thanks.

What Others Are Reading

Leave a Reply

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