skillfed

Kotlin Idioms

This skill covers core Kotlin idioms that make code safer and more expressive. Learn null-safety techniques, sealed hierarchies for type-safe results, structured concurrency with coroutines, and naming conventions. Includes practical examples and tooling guidance for formatting and static analysis.

Kotlin Idioms teaches idiomatic Kotlin coding patterns including null safety, data classes, coroutines, and testing best practices.

AI-generated summary based on this skill's SKILL.md

150 48 MIT updated by irahardianto

Install

irahardianto/awesome-agv/kotlin-idioms · repository language: JavaScript

git clone https://github.com/irahardianto/awesome-agv
cp -r awesome-agv/.agents/skills/kotlin-idioms ~/.claude/skills/kotlin-idioms
npx skillfed install irahardianto/awesome-agv/kotlin-idioms

Frequently asked questions

AI-generated answers based on this skill's SKILL.md and metadata

How do I write idiomatic Kotlin code that follows best practices?

Kotlin Idioms teaches you to leverage the language's unique features for safer, more expressive code. Focus on null-safety with the elvis operator (?:) and safe calls (?.), use sealed classes and data classes for type-safe domain models, prefer scope functions like let for concise transformations, and adopt exhaustive when expressions to catch missing cases at compile time. The skill emphasizes avoiding global scope launches in coroutines and using structured concurrency patterns instead.

What null safety patterns does Kotlin Idioms cover?

Kotlin Idioms covers null-safety through multiple patterns: safe calls (?.) to call methods only on non-null objects, the elvis operator (?:) to provide defaults, and require/check functions for explicit error handling. You'll learn to avoid platform types from Java interop by using nullable annotations, and understand how Kotlin's type system prevents null pointer exceptions at compile time rather than runtime.

How can I master coroutines and structured concurrency in Kotlin?

Kotlin Idioms teaches structured concurrency by showing how to avoid launching coroutines in global scope and instead use proper scope functions like coroutineScope and supervisorScope. You'll learn to manage cancellation, exception handling, and job hierarchies correctly, ensuring coroutines are tied to their parent scope and cleaned up predictably.

What coding conventions and naming rules does Kotlin Idioms teach?

Kotlin Idioms covers naming conventions including camelCase for properties and functions, PascalCase for classes, and UPPER_SNAKE_CASE for constants. The skill includes guidance on using ktlint and detekt for automated static analysis and code formatting, plus best practices like avoiding explicit getters/setters and following Kotlin's property naming conventions.

What are sealed classes and data classes in Kotlin Idioms?

Kotlin Idioms explains sealed classes as a way to restrict class hierarchies for type-safe results and discriminated unions, often paired with data classes for immutable value objects. Sealed interfaces offer modern alternatives for modeling restricted type hierarchies. Together they enable exhaustive when expressions that the compiler can verify are complete.

Does Kotlin Idioms cover testing and static analysis tools?

Kotlin Idioms includes guidance on setting up testing with kotest and MockK for unit and integration tests. It also covers static analysis tooling like ktlint for code formatting and detekt for code quality checks, helping you enforce idioms and conventions automatically across your codebase.

SKILL.md

rendered from the published skill — quoted content, verbatim

Kotlin Idioms and Patterns

Kotlin rewards conciseness, null safety, and coroutine-based concurrency. Idiomatic Kotlin = safe, expressive, interop-aware.

> Scope: Kotlin coding idioms. Test naming: .agents/rules/testing-strategy.md.

Null Safety

  1. ? for nullable types — never platform types without annotation: kotlin fun findById(id: String): Task? // explicitly nullable fun getById(id: String): Task // guaranteed non-null — throws if not found

  2. Prefer ?.let {} and ?: (Elvis) over null checks.

  3. Never !! in production — use requireNotNull with a message.

Data Classes and Sealed Types

  1. data class for DTOs and domain objects: kotlin data class CreateTaskRequest(val title: String, val priority: Priority)

  2. sealed class/sealed interface for restricted hierarchies: kotlin sealed interface TaskResult { data class Success(val task: Task) : TaskResult data class NotFound(val id: String) : TaskResult data class ValidationError(val errors: List<String>) : TaskResult }

  3. **Exhaustive when with sealed

(truncated - see the full file via the links below)

Read as markdown · JSON record · Browse the source repository

File tree — 1 file
.agents/skills/kotlin-idioms/SKILL.md

Related skills

Tags

null-safety-patterns functional-programming concurrency-model type-system code-style-guide testing-frameworks static-analysis-tools sealed-hierarchies reactive-streams interoperability-aware