Learning Kotlin

Intro

I’ve dabbled with Kotlin since Google announced it was an officially supported language for Android. I’m following lectures on Udemy covering basic syntax like val vs var and if/when expressions. I can already see the power of using these expressions to return their values for variables or functions.

The class will be covering the strengths of Kotlin, comparing them with Java, and avoiding some common pitfalls in Java. Kotlin objects are non-null by default. This helps avoid NPEs. Immutable objects are declared as val or assign once (read-only) values. Mutables are var or variables. if/when expressions can return values. var/val or fun can be assigned by their results. This helps write concise code.

Continuing Skills

The course is 9-10 hours long, so I’m taking an hour each day to learn something new in Kotlin. Today’s lesson will cover for/while loops and fun syntax. I’m looking forward to learning more about higher-order functions and lambdas along the way in this course.

It’s early this morning. I need some coffee.

Coffee Status

val coffee = 0
val status = when(coffee) {
    0 -> "no coffee"
    1 -> "1 coffee"
    else -> "$coffee coffees"
}
println(status) // no coffee