Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Kotlin

ASecurity

Language-specific super-code guidelines for kotlin.

7 stars
0 votes
0 copies
0 views
Added 9/22/2026
documentationgojavakotlinexpress

Works with

cli

Security Analysis

A100/100

Scanned 9/22/2026

$npx -y skills add JantonioFC/skillsbank --skill kotlin --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Kotlin?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Kotlin
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/jantoniofc-kotlin/badge)](https://www.skillsdirectory.com/skills/jantoniofc-kotlin)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
Files
SKILL.md
---
name: kotlin
description: "Language-specific super-code guidelines for kotlin."
risk: safe
source: community
date_added: "2026-06-16"
---
# Kotlin + Compose: Idiomatic Efficiency Reference

## Table of Contents
1. [Collections & Data Transformation](#collections)
2. [Null Safety](#null-safety)
3. [Functions & Lambdas](#functions)
4. [Classes & Objects](#classes)
5. [Coroutines & Flow](#coroutines)
6. [Compose UI](#compose)
7. [Anti-patterns specific to Kotlin](#antipatterns)

---

## 1. Collections & Data Transformation {#collections}

**Prefer scope functions and stdlib transforms over imperative loops.**

```kotlin
// ❌ 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() }
```

```kotlin
// ❌ 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 }
```

```kotlin
// ❌ 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}

```kotlin
// ❌ Unnecessary null check when Elvis suffices
val name: String
if (user?.name != null) {
    name = user.name
} else {
    name = "Guest"
}

// ✅
val name = user?.name ?: "Guest"
```

```kotlin
// ❌ Double null check
if (response != null && response.body != null) {
    process(response.body!!)
}

// ✅
response?.body?.let { process(it) }
```

```kotlin
// ❌ !! 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}

```kotlin
// ❌ Single-expression function with unnecessary block body
fun double(x: Int): Int {
    return x * 2
}

// ✅
fun double(x: Int) = x * 2
```

```kotlin
// ❌ Lambda capturing unused parameter
items.forEach { item -> doSomething() }

// ✅
items.forEach { doSomething() }
```

```kotlin
// ❌ 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}

```kotlin
// ❌ Mutable class for immutable data
class Point {
    var x: Int = 0
    var y: Int = 0
}

// ✅
data class Point(val x: Int, val y: Int)
```

```kotlin
// ❌ 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
```

```kotlin
// ❌ 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}

```kotlin
// ❌ Unnecessary async/await pair when result is used immediately
val result = async { fetchData() }.await()

// ✅
val result = fetchData() // just suspend fun, no async needed
```

```kotlin
// ❌ Collecting in a loop
while (true) {
    val value = channel.receive()
    process(value)
}

// ✅
channel.consumeEach { process(it) }
// or for Flow:
flow.collect { process(it) }
```

```kotlin
// ❌ 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}

```kotlin
// ❌ 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}"
```

```kotlin
// ❌ 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) }
```

```kotlin
// ❌ 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
```

```kotlin
// ❌ 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.**

---

## 7. Anti-patterns specific to Kotlin {#antipatterns}

| 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 |



## Limitations
- These are language-specific guidelines and do not cover overall architectural decisions.
- Over-compression might reduce readability; apply judgement.

Attribution

JantonioFCJantonioFC
View sourceSee grades on GitHubMore from JantonioFC →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Context Fundamentals

Understand the components, mechanics, and constraints of context in agent systems. Use when designing agent architectures, debugging context-related failures, or optimizing context usage.

179001 votes

Architecture Diagram Creator

Create comprehensive HTML architecture diagrams with data flows, business context, and system architecture.

6661 votes

release-notes

Draft release notes and changelog entries from git history or merged PRs between two refs (tags/SHAs/branches), including breaking changes, migrations, and upgrade steps. Use when the user asks for release notes, changelog updates, or a GitHub Release draft.

1301 votes

docs-style-guide

Documentation style guide enforcer by @planetabhi. Applies and reviews the writing style guide when authoring or editing product documentation and tutorials. Use to check prose for voice, tense, word choice, inclusive language, formatting, code block, UI, Markdown, and number/date conventions.

11 votes

Docx

Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in W...

1798860 votes
View all in documentation →