본문으로 건너뛰기
Skillpedia
일반 코딩48k · #5894

kotlin

하는 일

이 가이드는 모범 사례를 따라 더 효율적이고 명확한 Kotlin 코드를 작성하는 방법을 가르칩니다. 언어 기능을 사용해 흔한 프로그래밍 작업을 단순하게 만드는 방법을 보여 줍니다.

사용하는 경우

  • ✓Kotlin으로 프로그래밍을 배울 때.
  • ✓기존 Kotlin 코드를 검토하거나 개선할 때.
  • ✓더 간결하고 읽기 쉬운 코드를 쓰고 싶은 경우.

스킬 링크

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/kotlin/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/kotlin/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“스코프 함수를 사용해 이 Kotlin 코드를 더 깔끔하게 만들어 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

이 가이드는 '나쁜' 코드 예시와 '좋은' 예시를 비교해 모범 사례를 보여 줍니다. Kotlin에 내장된 도구를 사용해 반복적이거나 복잡한 코드를 피하는 데 중점을 둡니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 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

  1. Collections & Data Transformation
  2. Null Safety
  3. Functions & Lambdas
  4. Classes & Objects
  5. Coroutines & Flow
  6. Compose UI
  7. 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 }


…
자주 묻는 질문

'스코프 함수'란 무엇인가요?

`let`, `run`, `apply` 같은 특별한 Kotlin 함수로, 객체에 대해 코드 블록을 실행해 코드를 더 읽기 쉽게 만듭니다.

'Null Safety'란 무엇인가요?

값을 가져야 하는데 비어 있어서(null) 생기는 흔한 오류를 막아 주는 Kotlin 기능입니다. 가이드는 이를 안전하게 다루는 방법을 보여 줍니다.

'코루틴'이란 무엇인가요?

인터넷에서 데이터를 가져오는 것처럼 시간이 걸리는 작업을 애플리케이션을 멈추지 않고 처리하는 방법입니다. 가이드는 이를 효율적으로 사용하는 방법을 제안합니다.

상세 정보

작성자의 원본 설명

Language-specific super-code guidelines for kotlin.

repo: sickn33/agentic-awesome-skills

인기도

GitHub 스타
48k
순위
#5894
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬