History and Current Status
Many a times we have heard about or seen firsthand the drawbacks of Java.
Though it is most used in Enterprise Software development, Java is:
-
Highly Verbose
Kotlin makes a lot of verbose aspects of the Java Class Library much shorter with its ability to
infer types of variables while also retaining options to declare types.
-
Needs a lot of Boilerplate coding
Kotlin reduces the amount of boilerplate code with its concise syntax and much better functional aspects
which we do not usually see in Java code.
-
Prone to accidental complexity
Kotlin's power lies in using its safer types and functional aspects like higher-order function in order
to make our programs as simple and straighforward as possible.
Even after all the shortcomings of Java, there is little argument about the Java Virtual Machine (JVM).
JVM is a masterpiece of Software Engineering and offers a battle-hardened runtime that has passed the test of time.
Over the years, JVM languages like Scala tried to answer the shortcomings of Java and wanted to better Java,
but failed.
Finally, in Kotlin, it looks like a search for a better Java is over.
Jet Brains (the company behind the popular IDE IntelliJ) has developed Kotlin along with many open Source contributors,
which runs on JVM and answers the shortcomings of Java and offeres many modern features.
The best part is that unlike Scala, Kotlin is much simpler than Java and offers Go or Python-like developer productivity in JVM.
Google has declared Kotlin as a first-class language to develop Android and boosted Kotlin’s acceptance in the community.
Also, popular Java Enterprise framework Spring has started to support Kotlin in the Spring eco-system since 2017
Source .
As of November 15, 2020, the Kotlin Website provides version 1.4.10 of the Kotlin Language.
And you can also get an compiler with either the IntelliJ IDEA
or on the command line.
Though Kotlin supports type inference, we can still optionally declare types of our variables and we must do
so if we are not initializing them. We must also specify return types for functions.
A programmar can also create new types in the form of classes. An interesting thing about Kotlin is that
It gives us great control over nullability of types are only the Objects ending with ? (For example: String?) are nullable.
The Functions in Kotlin are first-class objects.
Kotlin supports both iteration and recursion.
-
If statement
Kotlin has a powerfull if - else statement and ternary operators. It also has other interesting operators like the Elvis
Operator (?:) which is used for nullability assignment and comes in very handy.
-
When Statement
Kotlin's When statement is very much like Java's switch statement but it has a slightly different syntax.
The statement actually returns a reference to what case was processed and can therefore also be used in assignment
of any variable.
-
Iteration
Kotlin has a highly versatile for loop which has many
different forms and iteration options. But the most powerful iterator by far is the forEach higher-order
function which has many iteration and index option for almost all of the existing data structures.
Kotlin allows us to significantly reduce the amount of code we need to write to achieve the same functionality.
This make sit slightly irregular since there are multiple ways to do things and leads to a loss of generality in our code.
But the functional features gained are worth the trade. Kotlin is a mixed bag in terms of Orthogolanity, though it does away
with Java's distinction of Primitive and Non-Primitive types, it does introduce the distinction between Nullable and non-Nullable
types. This leads to better null pointer safety but can be looked upon as a loss in Orthogolanity.
Kotlin is also a pretty uniform language as most of its contructs of control flow and class declaration look pretty similar.