> kotlin-language
Idiomatic Kotlin 1.9+ standards (Null Safety, Expressions, Extensions). Use when working with Kotlin null safety, expression syntax, or extension functions. (triggers: **/*.kt, **/*.kts, val, var, extension, data class, sealed, when)
curl "https://skillshub.wtf/HoangNguyen0403/agent-skills-standard/kotlin-language?format=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
> related_skills --same-repo
> typescript-tooling
Development tools, linting, and build config for TypeScript. Use when configuring ESLint, Prettier, Jest, Vitest, tsconfig, or any TS build tooling. (triggers: tsconfig.json, .eslintrc.*, jest.config.*, package.json, eslint, prettier, jest, vitest, build, compile, lint)
> typescript-security
Secure coding practices for TypeScript. Use when validating input, handling auth tokens, sanitizing data, or managing secrets and sensitive configuration. (triggers: **/*.ts, **/*.tsx, validate, sanitize, xss, injection, auth, password, secret, token)
> typescript-language
Modern TypeScript standards for type safety and maintainability. Use when working with types, interfaces, generics, enums, unions, or tsconfig settings. (triggers: **/*.ts, **/*.tsx, tsconfig.json, type, interface, generic, enum, union, intersection, readonly, const, namespace)
> typescript-best-practices
Idiomatic TypeScript patterns for clean, maintainable code. Use when writing or refactoring TypeScript classes, functions, modules, or async logic. (triggers: **/*.ts, **/*.tsx, class, function, module, import, export, async, promise)