원클릭으로
kotlin
Language-specific super-code guidelines for kotlin.
메뉴
Language-specific super-code guidelines for kotlin.
Optimize pull requests for quick approval and merging by ensuring clean diffs, comprehensive self-reviews, and structured documentation.
Frontend design entry point: direction, design system, visual philosophy. Use whenever building or touching the look of any web UI (components, pages, dashboards, React/Vue/HTML-CSS) or when the user says "make this look better", "fix the spacing/layout", or mentions styling, color, type, or polish.
Render the UI and prove it's balanced + usable: a deterministic layout audit (centroid / optical-center / pixel-oracle balance via explicit math + annotated screenshot) plus a vision-judged Nielsen usability audit by a separate fresh-eyes judge. The measurement layer taste-only design skills lack.
Automated visual tuning: a vision or video model rates rendered variants in a loop. Render several labeled variants into one artifact, ask the model to rate them and suggest better values, render the suggestions, ask it to pick the best, repeat until good — the model is the eye, you run the loop.
Human-in-the-loop web studio to tune AI-generated output by eye. Stand up a local interactive studio (sliders, pickers, drag handles) or an inline edit/highlight/comment annotation studio for prose & media, instead of guessing values or shipping a static comparison grid.
macOS screen recorder that captures the main display PLUS system audio via ScreenCaptureKit — no BlackHole/loopback driver, no sudo, just the standard Screen Recording permission. CLI-driven; fills the headless-screen-recording-with-system-sound gap QuickTime and `screencapture -v` can't.
| name | kotlin |
| description | Language-specific super-code guidelines for kotlin. |
| risk | safe |
| source | community |
| date_added | 2026-06-16 |
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.
// ❌ 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
// ❌ 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.
// ❌ 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.
// ❌ 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.
// ❌ Unnecessary remember for derived state that's cheap to compute
val displayName = remember { user.firstName + " " + user.lastName }
// ✅ — only remember if computation is expensive or involves object creation
val displayName = "${user.firstName} ${user.lastName}"
// ❌ Passing entire state object when composable only needs one field
@Composable
fun UserBadge(user: User) { Text(user.name) }
// ✅ — pass only what's needed (stability + minimal recomposition)
@Composable
fun UserBadge(name: String) { Text(name) }
// ❌ Inline click handler lambda (creates new instance each recomposition)
Button(onClick = { viewModel.onSave() }) { ... }
// ✅
val onSave = remember { { viewModel.onSave() } }
Button(onClick = onSave) { ... }
// Or pass it down as a parameter already
// ❌ Nested Column/Row just to group children
Column {
Column {
Text("a")
Text("b")
}
}
// ✅
Column {
Text("a")
Text("b")
}
Use LazyColumn/LazyRow for lists of unknown or large size. Never put a LazyColumn inside a Column with unbounded height.
| Anti-pattern | Preferred |
|---|---|
if (x == true) | if (x) |
if (x == null) return else x!! | val x = x ?: return |
listOf().toMutableList() for a known-size list | mutableListOf() |
when with a single branch and else | if/else |
.toString() on a string | remove it |
Explicit Unit return type on functions | omit (inferred) |
object : Runnable { override fun run() { ... } } | Runnable { ... } (SAM) |
@JvmStatic in pure Kotlin code | only needed for Java interop |
| Wrapping every function in try/catch to log | handle at the boundary, not inside |