Introduction

Kotlin is a programming language made in order to address the many shortcomings of Java. It is very versatile and can run on a Java Virtual Machine (JVM), compile to Native Code via LLVM, or used for web applications and development by compiling to JavaScript. It can interoperate fully with Java and depends on the Java Class Library.

https://aster.cloud/wp-content/uploads/2019/05/kotlin-logo.jpeg

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.

https://image.shutterstock.com/image-vector/objectoriented-programming-icon-trendy-logo-260nw-1227065041.jpg

Paradigm

Kotlin is an Object-Oriented Language by design. But like most of the new languages that have emerged recently, it has a tremendous number
of functional language features like lambdas and higher order functions.

Typing

Kotlin is strongly statically typed as it does not support implicit conversion between incompatible types.

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.

Control Structures

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.

Semantics

Kotlin is a statically scoped language just like Java. It can have two types of variables: vars and vals. vars are what we would expect from a regular variable and vals are constants which cannot be changed once assigned. These are dynamic constants.
Memory allocation is always heap-dynamic in Kotlin but the Kotlin compiler can optimise code and place of objects in either stack or global memory. Kotlin is a garbage collected language just like Java. It allocates and frees memory automatically in the background for our program.

https://miro.medium.com/max/3840/1*YEfXspCXQp1oOHQbdHzyDA.jpeg

Desirable Language Characteristics

Kotlin's strengths lie in its improvements over Java.
I will focus on how the language does better in terms of regularity and how it fares worse.

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.

Project

Here you will find Part 3 of the Project requirements.

Get Started with Kotlin

Ready to embrace Kotlin as your go-to language?
It's no surpise.