Cover image for Mobile app development: sharing experience in Kotlin coding

Mobile app development: sharing experience in Kotlin coding

dianamaltseva8 profile image Diana Maltseva ・3 min read

Once officially released on February 2016 Kotlin fastly became a hot programming language. Kotlin is a statically-typed programming language developed by JetBrains and running on the Java Virtual Machine. Also, it can be compiled to JavaScript source code or JVM bytecode.

Custom mobile app development on Kotlin programming language offers many advantages. First, the main aim of JetBrains was to make it as quick as Java and easy to learn. And they managed to do that.) Second, Kotlin provides lean syntax, extensions features, null-pointer safety, and infix notation.

One of the strong and important things there is the fact that Kotlin language came from the industry, not academia. It was developed to solve programmers’ difficulties and operational challenges.

We also supported this technology trend and made 2 experiments in using Kotlin:

  1. Moving Java written project to Kotlin language
  2. Project development on Kotlin from scratch

We wanted to pay special attention to Kotlin features that Java doesn’t have. Here is a list of the most interesting and useful Kotlin introductions:

  • Lambda expressions + Inline functions = performance custom control structures
  • Extension functions
  • Null-safety
  • Smart casts
  • Properties
  • Companion objects
  • Primary constructors

Moving Java project to Kotlin programming language

JetBrains took care of the ability of automatic conversion of Java classes to Kotlin ones. Making the conversion of different project classes we received the following results: we got Kotlin code, on the average 20-25% less than the same on Java.

So, we made sure that Kotlin language allows to write more elegant and concise code. This is the most visible in model classes as Kotlin Properties allow to dispense with getters and setters.

Also we were pleased by Smart Class: even a person who understands nothing in programming will be able to put value of simplicity and sophistication of code written in Kotlin programming language comparing it with Java:

// Java code:

if (getActivity() instanceof LoginActivity)

((LoginActivity) getActivity ()). register ();

// Kotlin code:

if (activity is LoginActivity)

activity. register ()

Project development on Kotlin language from scratch

Product development on Kotlin gave us even more pleasant impressions. We believe that Kotlin Android Extensions should be described first of all.

Every Android app developer knows well a findViewById() function. Without a doubt, it’s a source of potential bugs and nasty code which is difficult to read and support.

While there are several available libraries that provide solutions to this problem, there are libraries dependent on runtime and requiring annotating fields for each View.

Also, a Kotlin Android Extensions plugin enabled us to obtain similar experience we had with some of these libraries, without having to add any extra code or shipping any additional runtime.

In Kotlin class developers can directly use a view’s id without additional initialization or leading to the required type as this language will take care about it itself. So, as an example, there is no necessity to use ButterKnife library for dependency injection.

Someone may object that listeners’ initialization takes a lot of place and looks unattractively while the very ButterKnife allows to eliminate this problem. Nevertheless, here Kotlin programming language successfully copes without third-party libraries: Lambda expressions and inline functions provide everything you need to write a concise, intuitive, and perfectly working code.

In our custom mobile app development we used a lot of utility classes for not to load Activities and Fragments with extra logic. For example, to completely implement the display of Toast system message throughout the application improperly.

That’s why we moved this in utility class. However, to display this message app developers have to always transfer a Context system object. Thanks to Kotlin Extension Functions we can add a method to a Context native class.

Compare method calls for Toast message display:
// Java code:

      ToastUtils.showMessage (context, “message”);

// Kotlin code:


Looks great, doesn’t it?

Thus, we received positive impressions from writing in Kotlin thanks to the advantages and smart introductions it provides engineers with. We believe in the potential of this programming language and plan to continue gaining experience in our custom mobile app development.

Lear more about Kotlin project experiments and Kotlin benefits https://smartym.pro/blog/sharing-experience-in-coding-in-kotlin/.


Editor guide
andy profile image
Andy Zhao (he/him)

Great post! I don't know a thing about mobile development, Java, or Kotlin, but I felt pretty comfortable reading the whole post.

Kotlin seems to be a going on an upward trend this year; do you think it'll eventually be the main language that most Android devs use?

dianamaltseva8 profile image
Diana Maltseva Author

Glad you've liked the post. For now, Kotlin sees rapid growth and attracts a lot of attention. As you probably know, recently Kotlin founders released a new version (Kotlin 1.1.2) with many improvements. What's more, Android announced Kotlin official support. Comparing to Java, Kotlin is more simple and no less quick. So, I believe, it has the potential to become the main language for Android dev.