Procedural programming in Kotlin
While Kotlin is a pure OOP language, it also supports procedural programming. This means that functions and variables can be defined without placing them explicitly in classes, unlike Java and compiled Scala code. (As we have seen earlier, Scala does not require functions and variables to be placed in classes when using its REPL; it requires this when using the standalone scalac
compiler.)
When not using Kotlin's REPL interactive shell to write programs, you'll make use of the Kotlin compiler. When you use the compiler to compile your source code, you can place both the functions and properties at the top level of a source file. We have been doing this for a while now in this chapter:
fun function1 { println("function1 is running...") } var property1: String = "default value of property1"
It's not possible to place executable code at the top level in the source code, though. Executable code must always reside in a function. To create a JVM...