LearnAI ToolsCareerPractice BuildsPlayContact
Lesson 1216 min read

Best Practices & Next Steps

Wrap up with idiomatic Kotlin style, scope functions, common conventions, popular frameworks, and where to go next after this course.

Introduction

You've covered Kotlin's core language features — from null safety to coroutines. This final lesson ties everything together with the idioms and conventions that separate code that merely compiles from code that reads as genuinely idiomatic Kotlin, plus a look at where the ecosystem goes from here.

You'll cover official coding conventions, the five "scope functions" that appear constantly in real Kotlin code, a short complete example putting several lessons together, the frameworks worth knowing next, and recommended next steps.

Coding Conventions

JetBrains publishes official Kotlin coding conventions at kotlinlang.org, and most tooling (including IntelliJ's default formatter) follows them out of the box.

  • Use four spaces for indentation, never tabs.
  • Name classes and objects with UpperCamelCase; name functions and properties with lowerCamelCase.
  • Prefer expression bodies (`fun square(x: Int) = x * x`) for simple, single-expression functions.
  • Keep lines to a reasonable length (roughly 100–120 characters) for readability.
  • Omit semicolons — Kotlin doesn't require them at the end of statements, and idiomatic code never includes them.

Scope Functions: let, apply, run, also, with

Kotlin's standard library defines five closely related "scope functions" that execute a block of code in the context of an object. They look similar but differ in two ways: whether they refer to the object as `it` or `this` inside the block, and what they return.

FunctionRefers to Object AsReturns
letitthe lambda's result
runthisthe lambda's result
withthisthe lambda's result
applythisthe original object
alsoitthe original object
data class Config(var host: String = "", var port: Int = 0)
fun main() {
// let: run code on a non-null value, return a transformed result
val length = "Kotlin".let { it.length }
println(length)
// apply: configure an object's properties, return the object itself
val config = Config().apply {
host = "localhost"
port = 8080
}
println(config)
// also: perform a side effect (like logging), return the object unchanged
val numbers = listOf(1, 2, 3).also { println("Created list: $it") }
println(numbers)
}
Output

Click Run to see what this code prints.

A common, practical rule of thumb: use `let` with a safe call (`value?.let { ... }`) to run code only when a nullable value isn't null; use `apply` to configure an object's properties right after construction; use `also` for side effects like logging that shouldn't change what gets returned.

Writing Idiomatic Kotlin

Beyond individual features, idiomatic Kotlin has a recognizable style: it favors immutability (`val` over `var`), expressions over statements (`if`/`when` returning values), null safety operators over defensive null checks scattered everywhere, and data/sealed classes over hand-written boilerplate.

Immutability First

Default to val and read-only collections; introduce mutability only where genuinely needed.

Expressions Over Statements

Use if and when as expressions that produce values, rather than mutating a var across branches.

Null Safety, Not !!

Reach for ?., ?:, and smart casts before ever reaching for the not-null assertion.

Data & Sealed Classes

Model data with data class and fixed outcome sets with sealed class instead of hand-rolled equals()/hashCode().

Popular Kotlin Frameworks

Once you're comfortable with the language itself, these are the ecosystems where Kotlin is most widely used in production.

FrameworkDomain
Jetpack ComposeModern, declarative Android (and increasingly multiplatform) UI toolkit built entirely in Kotlin.
KtorLightweight, coroutine-based framework for backend services, built by JetBrains.
Spring Boot (with Kotlin)The dominant Java enterprise framework, with first-class Kotlin support for backend APIs.
Kotlin MultiplatformShare business logic across Android, iOS, desktop, and web from one codebase.

A Complete Example

Here is a small program that ties together data classes, null safety, collections, and a when expression — several of the topics from this course working together.

data class Product(val name: String, val price: Double, val stock: Int)
fun describeStock(product: Product): String = when {
product.stock == 0 -> "${product.name} is out of stock"
product.stock < 5 -> "${product.name} is low on stock (${product.stock} left)"
else -> "${product.name} is well stocked"
}
fun findCheapest(products: List<Product>): Product? =
products.minByOrNull { it.price }
fun main() {
val products = listOf(
Product("Keyboard", 49.99, 12),
Product("Mouse", 19.99, 0),
Product("Monitor", 199.99, 3)
)
products.forEach { println(describeStock(it)) }
val cheapest = findCheapest(products)
println("Cheapest: ${cheapest?.name ?: "No products found"}")
}
Output

Click Run to see what this code prints.

Where to Go Next

  • Build a small Android app with Jetpack Compose to see Kotlin's null safety and coroutines used in a real UI context.
  • Try Ktor or Spring Boot to build a backend REST API entirely in Kotlin.
  • Explore Kotlin Multiplatform to share logic between Android and iOS from one codebase.
  • Go deeper on generics, delegated properties, and inline functions — advanced language features not covered in this beginner course.
  • Read the official Kotlin documentation and coding conventions at kotlinlang.org as your ongoing reference.

Common Mistakes

Avoid These Mistakes
  • Writing "Java in Kotlin syntax" — using var everywhere, manual getters/setters, and null checks instead of Kotlin's own idioms.
  • Reaching for the wrong scope function out of habit — mixing up `let`/`run`/`apply`/`also` is common at first; check what each one returns before choosing.
  • Ignoring compiler warnings about nullability or unused `!!` — they usually point directly at a real, avoidable risk.
  • Learning Kotlin syntax without also learning its standard library — much of Kotlin's expressiveness comes from library functions like map/filter/let, not just language keywords.

Best Practices

  • Let IntelliJ's built-in Kotlin inspections guide you — many suggest more idiomatic rewrites automatically ("convert to expression body," "use safe call," etc.).
  • Read real, well-regarded open-source Kotlin projects (like Ktor itself) to see idiomatic style in practice.
  • Practice by rewriting small pieces of Java code you know into Kotlin — it's a fast way to internalize the differences.
  • Keep null safety, data classes, and sealed classes as your default tools for modeling data — they solve the majority of everyday design problems cleanly.

Frequently Asked Questions

Most learners find the opposite — Kotlin's concise syntax and helpful compiler errors (especially around null safety) tend to make it faster to become productive in, even for complete beginners.

Either is a reasonable next step — pick based on your interests. Android (Jetpack Compose) gives you a visual, app-based project; Ktor or Spring Boot gives you an API/backend-focused project.

Yes. Kotlin's backend usage (Ktor, Spring Boot) and Kotlin Multiplatform adoption have both grown steadily, and the language's core strengths — null safety, conciseness, coroutines — apply equally outside of Android.

Key Takeaways

  • Idiomatic Kotlin favors val, expressions over statements, and null-safety operators over !!.
  • The five scope functions (let, run, with, apply, also) differ in how they refer to the object (it vs this) and what they return.
  • Data classes and sealed classes are the idiomatic way to model data and fixed outcome sets, respectively.
  • Jetpack Compose, Ktor, Spring Boot, and Kotlin Multiplatform are the major frameworks to explore next.
  • The official documentation and coding conventions at kotlinlang.org are the best ongoing reference as you keep learning.

Summary

Across this course, you've gone from "Hello, Kotlin!" through null safety, classes, collections, data and sealed classes, and coroutines — the core toolkit for writing real Kotlin programs. From here, the best next step is to build something real: a small Android app, a backend API, or a multiplatform project, applying everything you've learned along the way.