Reasons why should NOT start coding with Kotlin
How Kotlin is a modern programming language
If you are starting to learn how to code, take another language like Java, JavaScript, or C/C++. Do not start learning how to code with Kotlin. As a popular opinion among developers over the world,
Kotlin improves Java’s weakness which is very rigid and hard to code which results in less productivity. Kotlin has the same purpose as Scala, it introduces a lot of patterns to code less and thus improved productivity for programmers. Kotlin also introduces functional programming which is loved by many programmers.
In my words, Kotlin was created with the ambition to reduce a lot of boilerplate code from Java and add extra features that Java cannot include because of the way it has been built.
I am a teacher at Schoolhouse.world where I hosted a course where I’d teach Kotlin to students who would like to learn the language. Some of my students did not know to program while others knew the basics. I came to realise that students who didn’t know how to program were finding Kotlin very complex while those who did loved the language as a whole.
Let me illustrate how this is happening:
Creating Classes
This is the class that you would have to write in Java for creating a Person model. And in Kotlin, you ask? In Kotlin, all you have to write is:
Now, from a perspective of a learner: he/she is not getting exposed to what’s happening under the hood. He/She is not aware of the generated functions or does not quite understand the toString()
method or the equals()
method.
From a perspective of a tutor: it is difficult to explain where exactly the idea of data classes comes from if the learner doesn’t already have some background knowledge of programming.
Primary and Secondary Constructors
The most confusing topic my students found were the primary and secondary constructors in Kotlin. Those who had little to no knowledge of programming did not quite understand the need of multiple constructors and the flow of the program, especially when it included Inheritance.
The usage of primary and secondary constructors along with the
init
block — when and when not to declarevar/val
in the constructor parameters — is complex as it gets difficult to visualise the processes below the hood, as opposed to Java.
The variety of functions
In Java, we have the plain old simple function. But Kotlin comes with,
1. Infix functions.
2. Extension functions.
3. Operator functions.
4. Tailrec functions.
5. Inline functions.
And each function has a different meaning and usage. Coming from a background with no experience, learning this could be overwhelming.
Nullable and Non-nullable types
Kotlin is among the few popular languages where every type is divided into a nullable and non-nullable type. This improves the programmer’s productivity and keeps the program null-safe, but again, learning it at first can be daunting because of the extra work you’re needing to do.
Scope functions
This topic is something we didn’t think we need, but we are glad it exists — in my opinion. Scope functions allows easy manipulation of variable data, and bypass nullability issues. It also gives the opportunity to programmers to come up with their own unique code style using these functions.
Intent(this, SecondActivity::class.java).apply {
putExtra("key_count", count)
flags = Intent.FLAG_ACTIVITY_NEW_TASK
}.also {
startActivity(it)
}
Support for both Object Oriented and Functional Programming
Kotlin is a language that very cleverly uses features of both Object Oriented Programming as well as Functional programming, often in the same file. Coding functions in a traditional way and also having them as variables can be daunting at first to a programming newbie.
Here’s an example of a program I use to solve Competitive Programming problems in Kotlin. The usage of higher-order functions is complex for a beginner and cause many to drop programming due to its difficulty.
Miscellaneous Mentions
Kotlin does not stop with improving the weaknesses of Java. There are numerous other concepts that Kotlin entails.
1. lateinit
properties — these properties do not have an initial or default value and they must be initialised before usage.
2. Property/Class Delegation — A modern way of delegating functions to a class or a property.
3. lazy
loading — Declaring variables by lazy
would mean they would only be initialised when they are first needed.
4. if
and when
expressions — shorten and improve your code with if
and when
expressions.
And the list does not end!
Conclusion
Kotlin is one of the superior languages out there right now, if not the best. Kotlin can be used to create cross-platform applications, websites and servers at the moment.
You may start learning how to program with Kotlin, but it is going to be difficult and it would take a longer time to get adjusted with programming. In my opinion, languages like Java or JavaScript is the best to start with and then move on to a language like Kotlin.
With prelimary knowledge of programming, learning Kotlin is not that big of a leap.
I hope you enjoyed my article. Thank you for reading! ✌️
Want to connect?https://github.com/cybercoder-naj
https://www.linkedin.com/in/nishant-a-jalan