Programming in Kotlin

A multi-paradigm programming language

Nishant Aanjaney Jalan
CodeX

--

I consider Kotlin to be a very superior language, and it is also my favourite. Kotlin was created to implement various language features, inspired by other languages like Python and Java (obviously) and reduce the amount of boilerplate code to improve developer productivity. Kotlin titles itself as:

A modern programming language that makes developers happier.

Photo by Marc Reichelt on Unsplash

Why should you learn Kotlin?

Kotlin is an evolving programming language built by Jetbrains. They started the development in 2013, and its first stable release was in 2016. Later, Google switched from Java to Kotlin as its preferred programming language for Android Applications in 2019.

If you are an experienced programmer, you will find that Kotlin uses many language features you might have seen in other languages. This includes:

  1. Functional programming from JavaScript.
  2. Object-Oriented programming from Java.
  3. Laziness from Haskell.
  4. Miscellaneous features like String Templating from Python or PHP.

Kotlin vs Java

It is never a good idea to directly compare two programming languages. But it is not a harm to discuss the improvements Kotlin bring and the drawbacks it has.

Improvements

  1. Lesser code — In Java, to write a simple Hello World program, you would have to create a class and a long main method to do so. Of course, most of that has been automated; however, lesser code equates to more maintainability.
  2. Null Safety — In Java, all objects were allowed to be nullable. This was a big mistake when languages like C and C++ came along. Kotlin is, however, strict about nullability. You can allow an object to be null only if you want it to be.
  3. Functional Programming — In recent developments, Java has improved to support some functional programming support. But Kotlin has surpassed Java in this case. Kotlin has in-built support for functional programming that makes it seamless.
  4. Reduced Boilerplate — The introduction of data class has been a major improvement in transforming a 50-line POJO (Plain Old Java Object) class to a handful of 5 lines.

Drawbacks

  1. Slow compilation — Due to the extensive features Kotlin has to offer, it takes longer to compile than an equivalent Java program.
  2. Checked exceptions — Kotlin does not support the use of checked exceptions. Your Kotlin code will compile without a try-catch(-finally) block even if you perform basic I/O operations.
  3. Complex language — I have had the opportunity to teach Kotlin in the past, and in my experience, Kotlin is not an easy language to learn. Those who have experience in other languages like Python and Java can adapt to this efficiently. However, a beginner with no programming experience will need more time to take in everything that Kotlin provides.

A fun fact and a joke: Kotlin is a language that is written in itself! The creators of Kotlin hated Java so much that once they got to the stable release, they migrated their code to Kotlin. 😀

Kotlin for Android Development

In 2019, Google announced that they are shifting their preferred language to Kotlin. There have been multiple improvements after this shift which not necessarily could have happened had Java remained their official language.

  1. Coroutines — Java developers had multiple problems maintaining Android code that required concurrency. Since running background tasks on a UI thread raised exceptions, they had to rely on classes like Handler, and AsyncTask. Kotlin developers ditched the idea of multithreading and use Coroutines to conduct the same tasks. Coroutines are lightweight processes that run in suspension inside like or unlike threads.
  2. Jetpack Compose — For many years, Android relied on a markup language, XML, to code the front end of the application. Jetpack Compose is now officially stable and it is the preferred way to create UI in Android, leveraging the powers of Kotlin.

Conclusion

Kotlin is an ever-growing language where there are improvements with every update. It is a powerful language that increases developer productivity. It is amazing to see the gaining recognition and popularity of this gem of a language today.

This article is the first entry to my “Kotlin Programming Course” on Medium. It is separate from my other reading list “Everything Kotlin” which is more towards the advanced programming features of Kotlin.

Kotlin Programming Course

3 stories

Everything Kotlin

22 stories

I hope you enjoyed reading my article and learnt something. Thank you! ✌️

Want to connect?My GitHub profile.
My Portfolio website.

--

--

Nishant Aanjaney Jalan
CodeX
Editor for

Undergraduate Student | CS and Math Teacher | Android & Full-Stack Developer | Oracle Certified Java Programmer | https://cybercoder-naj.github.io