Agent skill
Kotlin Language Patterns
idiomatic Kotlin 1.9+ standards (Null Safety, Expressions, Extensions).
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/language-hoangnguyen0403-agent-skills-standar-2
Metadata
Additional technical details for this skill
- labels
-
kotlin language idioms null-safety
- triggers
-
{ "files": [ "**/*.kt", "**/*.kts" ], "keywords": [ "val", "var", null, "extension", "data class", "sealed", "when" ] }
SKILL.md
Kotlin Language Patterns
Priority: P0 (CRITICAL)
Modern, idiomatic Kotlin standards for safety and conciseness.
Implementation Guidelines
- Immutability: Use
valby default. Only usevarif mutation is required locally. - Null Safety: Use
?for nullable types. Use safe call?.and Elvis?:over!!. - Expressions: Prefer expression bodies
fun foo() = ...for one-liners. Useifandtryas expressions. - Classes: Use
data classfor DTOs. Usesealed interface/classfor state hierarchies (Result, UIState). - Extension Functions: Prefer extensions over utility classes (
StringUtil). Keep them private/internal if specific to a module. - Named Arguments: Use named arguments for clarity, especially with booleans or multiple params of same type.
- String Templates: Use
"$var"over concatenation. Use"""for multiline strings (SQL/JSON).
Anti-Patterns
- Not-null Assertion (
!!):**No !!**: Never use in production code; use safe calls or requireNotNull. - Java-isms:
**No get/set prefixes**: Use properties. Prefer top-level functions over companion object statics. - Lateinit Abuse:
**Avoid lateinit var**: Prefer nullable types or lazy delegates. - Empty Catch:
**No Silenced Errors**: Never swallow exceptions without logging or handling.
Code
// Sealed Class + When Expression
sealed interface UiState {
data object Loading : UiState
data class Success(val data: List<String>) : UiState
data class Error(val message: String) : UiState
}
fun render(state: UiState) = when (state) {
UiState.Loading -> showLoading()
is UiState.Success -> showData(state.data)
is UiState.Error -> logError(state.message) // Smart cast
}
// Extension Function
private fun String.toSlug(): String = this.lowercase().replace(" ", "-")
Related Topics
best-practices | coroutines | android
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?