Kotlin Code Review: What Annoys Senior Developers

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

How Seniors See Your Kotlin Code: Analysis with Real Examples

\n\n

You wrote the code, pushed it to the repository, and are nervously waiting for approval. But instead of a green checkmark, a dozen comments from a senior developer arrive. Sound familiar? If you write in Kotlin, you've probably encountered a situation where your seemingly perfect code turns into a pumpkin after code review.

\n\n

In this article, we'll look at which typical senior developer comments are most often encountered during Kotlin code review. We won't teach you syntax — we'll show you how to write code that passes review on the first try. Let's go!

\n\n

1. Null Safety: "Why aren't you using the Elvis operator?"

\n\n

One of Kotlin's main features is null safety. But many developers, especially those coming from Java, continue to write code in a "check-for-null-and-execute" style. Seniors notice this immediately.

\n\n

Bad Example (Java-style)

\n
fun getUserName(user: User?): String {\n    return if (user != null) {\n        user.name\n    } else {\n        "Unknown"\n    }\n}
\n\n

Good Example (Kotlin-style)

\n
fun getUserName(user: User?): String {\n    return user?.name ?: "Unknown"\n}
\n\n

Using the Elvis operator (?:) and safe call (?.) makes the code concise and readable. Seniors love it when you save lines without losing clarity. Remember: if (x != null) { ... } else { ... } is bad practice.

\n\n

2. Extension Functions: "Where are your utilities?"

\n\n

When you see a static utility class like StringUtils.capitalize(str), an experienced Kotlin developer will wince. Extension functions are what make Kotlin so elegant.

\n\n

Bad Example

\n
object StringUtils {\n    fun capitalize(text: String): String {\n        return text.replaceFirstChar { it.uppercase() }\n    }\n}\n\n// Usage\nval result = StringUtils.capitalize("hello")
\n\n

Good Example

\n
fun String.capitalizeFirst(): String {\n    return this.replaceFirstChar { it.uppercase() }\n}\n\n// Usage\nval result = "hello".capitalizeFirst()
\n\n

Seniors will say: "Why are you creating a junk object? Just extend the class!" Use extension functions — it improves readability and follows Kotlin best practices.

\n\n

3. Sealed Classes Instead of Enum: "Your enum is outdated"

\n\n

Enums in Kotlin are good, but sealed classes offer much more flexibility. Especially when you need to store different data types in the same hierarchy.

\n\n

Bad Example (enum)

\n
enum class Result {\n    SUCCESS,\n    ERROR,\n    LOADING\n}\n\nfun handleResult(result: Result) {\n    when (result) {\n        Result.SUCCESS -> // ...\n        Result.ERROR -> // ...\n        Result.LOADING -> // ...\n    }\n}
\n\n

Good Example (sealed class)

\n
sealed class Result {\n    data class Success(val data: List<Item>) : Result()\n    data class Error(val message: String, val code: Int) : Result()\n    object Loading : Result()\n}\n\nfun handleResult(result: Result) {\n    when (result) {\n        is Result.Success -> println("Data: ${result.data}")\n        is Result.Error -> println("Error: ${result.message}")\n        Result.Loading -> println("Loading...")\n    }\n}
\n\n

Senior developers will appreciate that you use sealed classes to represent states. This is one of the main senior kotlin tips — make type hierarchies explicit.

\n\n

4. Scope Functions: "You forgot about let, apply, and run"

\n\n

Scope functions (let, apply, run, with, also) are powerful

Blogs

Book Recommendations