Book Image

Mastering High Performance with Kotlin

Book Image

Mastering High Performance with Kotlin

Overview of this book

The ease with which we write applications has been increasing, but with it comes the need to address their performance. A balancing act between easily implementing complex applications and keeping their performance optimal is a present-day requirement In this book, we explore how to achieve this crucial balance, while developing and deploying applications with Kotlin. The book starts by analyzing various Kotlin specifcations to identify those that have a potentially adverse effect on performance. Then, we move on to monitor techniques that enable us to identify performance bottlenecks and optimize performance metrics. Next, we look at techniques that help to us achieve high performance: memory optimization, concurrency, multi threading, scaling, and caching. We also look at fault tolerance solutions and the importance of logging. We'll also cover best practices of Kotlin programming that will help you to improve the quality of your code base. By the end of the book, you will have gained some insight into various techniques and solutions that will help to create high-performance applications in the Kotlin environment
Table of Contents (12 chapters)

Ranges in Kotlin

To create ranges of variables in Kotlin, you can use the rangeTo extension function or the .. operator of Kotlin. We can create a range of any Comparable type.

Let's look at the following example:

fun main(args: Array<String>) {
val int = args[0].toInt()
if (int in 0..10) {
println(int)
}
}

In this example, we retrieve a value from the args array.

The args array contains command-line arguments that can be used to pass parameters or specify a configuration when an application is launched.

To run a program with parameters in IntelliJ IDEA, click Run and choose Edit Configurations...:

In the window that opens, you can paste parameters in the Program arguments field:

Press OK and run the application. The output will be as follows:

2

Decompiled to Java, it looks like the following:

public static final void main(@NotNull String[] args) {
...