kotlin
What it does
This guide teaches how to write more efficient and clear Kotlin code by following best practices. It shows how to use language features to simplify common programming tasks.
When to use it
- βWhen learning to program in Kotlin.
- βWhen reviewing or improving existing Kotlin code.
- βWhen wanting to write more concise and readable code.
Skill link
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/kotlin/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βHow can I make this Kotlin code cleaner using scope functions?β
5 new skills a week. 1 minute to read.
How it works
The guide compares 'bad' code examples with 'good' examples to illustrate best practices. It focuses on using Kotlin's built-in tools to avoid repetitive or complicated code.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Kotlin + Compose: Idiomatic Efficiency Reference
When to Use
- Use this skill when the task matches this description: Language-specific super-code guidelines for kotlin.
Table of Contents
- Collections & Data Transformation
- Null Safety
- Functions & Lambdas
- Classes & Objects
- Coroutines & Flow
- Compose UI
- Anti-patterns specific to Kotlin
1. Collections & Data Transformation {#collections}
Prefer scope functions and stdlib transforms over imperative loops.
// β Verbose
val result = mutableListOf<String>()
for (item in items) {
if (item.isActive) {
result.add(item.name.uppercase())
}
}
// β
Idiomatic
val result = items.filter { it.isActive }.map { it.name.uppercase() }
// β Manual grouping
val map = mutableMapOf<String, MutableList<Item>>()
for (item in items) {
map.getOrPut(item.category) { mutableListOf() }.add(item)
}
// β
val map = items.groupBy { it.category }
// β Manual fold
var total = 0
for (order in orders) total += order.amount
// β
val total = orders.sumOf { it.amount }
Use associate, associateBy, partition, flatMap, zip instead of manual equivalents.
2. Null Safety {#null-safety}
// β Unnecessary null check when Elvis suffices
val name: String
if (user?.name != null) {
name = user.name
} else {
name = "Guest"
}
// β
val name = user?.name ?: "Guest"
// β Double null check
if (response != null && response.body != null) {
process(response.body!!)
}
// β
response?.body?.let { process(it) }
// β !! without guard
val value = nullable!!.doSomething()
// β
Make the non-null contract explicit at the boundary
val value = requireNotNull(nullable) { "nullable must be set before calling X" }.doSomething()
// Or return early:
val n = nullable ?: return
3. Functions & Lambdas {#functions}
// β Single-expression function with unnecessary block body
fun double(x: Int): Int {
return x * 2
}
// β
fun double(x: Int) = x * 2
// β Lambda capturing unused parameter
items.forEach { item -> doSomething() }
// β
items.forEach { doSomething() }
// β Redundant with/apply nesting
val builder = Builder()
builder.setName("x")
builder.setAge(1)
val result = builder.build()
// β
val result = Builder().apply {
setName("x")
setAge(1)
}.build()
Prefer let, run, apply, also, with over repeated receiver references β but don't nest more than 2 levels deep.
4. Classes & Objects {#classes}
// β Mutable class for immutable data
class Point {
var x: Int = 0
var y: Int = 0
}
// β
data class Point(val x: Int, val y: Int)
// β Companion object just to hold a constant
class Foo {
companion object {
val TAG = "Foo"
}
}
// β
β top-level if only used in this file
private const val TAG = "Foo"
class Foo
// β Enum with when that has to be updated in two places
enum class Status { ACTIVE, INACTIVE }
fun label(s: Status) = when(s) { Status.ACTIVE -> "Active"; Status.INACTIVE -> "Inactive" }
// β
β put display logic on the enum itself
enum class Status(val label: String) { ACTIVE("Active"), INACTIVE("Inactive") }
Sealed classes/interfaces over enum when variants carry different data.
5. Coroutines & Flow {#coroutines}
// β Unnecessary async/await pair when result is used immediately
val result = async { fetchData() }.await()
// β
val result = fetchData() // just suspend fun, no async needed
// β Collecting in a loop
while (true) {
val value = channel.receive()
process(value)
}
// β
channel.consumeEach { process(it) }
// or for Flow:
flow.collect { process(it) }
// β StateFlow + manual emit boilerplate
private val _state = MutableStateFlow(initial)
val state: StateFlow<State> = _state
// ... in many places: _state.value = newValue
// β
β use update{} for atomic mutation
_state.update { it.copy(field = newValue) }
Don't launch coroutines in constructors or init blocks. Don't use GlobalScope.
6. Compose UI {#compose}
// β Unnecessary remember for derived state that's cheap to compute
val displayName = remember { user.firstName + " " + user.lastName }
β¦
FAQ
What are 'scope functions'?
These are special Kotlin functions (like `let`, `run`, `apply`) that help execute code blocks on an object, making code more readable.
What is 'Null Safety'?
It's a Kotlin feature that helps prevent common errors caused by variables that should have a value but are empty (null). The guide shows how to handle this safely.
What are 'Coroutines'?
They are a way to handle time-consuming tasks (like fetching data from the internet) without freezing the application. The guide suggests efficient ways to use them.
Details
Original description by the author
Language-specific super-code guidelines for kotlin.
Popularity
- GitHub stars
- 48k
- Ranking position
- #5894
- License
- MIT
- Updated
- 10/15/2026
Comments
- β¦
More skills from this repository
00-andruia-consultant
48kHelps your agent start or improve AI projects. It analyzes code, suggests tools, and creates action plans in Spanish.
007
48kLets your agent perform security audits and threat modeling. It's useful for protecting projects against attacks and vulnerabilities.
10-andruia-skill-smith
48kHelps your agent create or improve AI tools. It defines how tools work, writes documentation, and validates the structure.
20-andruia-niche-intelligence
48kLets your agent create a summary about a specific industry. It's useful for understanding the context, rules, usage patterns, and risks of a project, using reliable sources.
Similar skills
diffs
394kLets your agent produce a real, shareable diff of edits as a viewer link or image file, instead of a hand-written summary.
coding-agent
394kHelps your agent hand a larger coding job to Codex, Claude Code, or OpenCode as a background worker, then check on its progress.
gh-issues
394kHelps your agent find GitHub issues, pick the ones to work on, and open pull requests with fixes, including follow-up on review comments.