@booklib/skills 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +105 -0
- package/animation-at-work/SKILL.md +246 -0
- package/animation-at-work/assets/example_asset.txt +1 -0
- package/animation-at-work/references/api_reference.md +369 -0
- package/animation-at-work/references/review-checklist.md +79 -0
- package/animation-at-work/scripts/example.py +1 -0
- package/bin/skills.js +85 -0
- package/clean-code-reviewer/SKILL.md +292 -0
- package/clean-code-reviewer/evals/evals.json +67 -0
- package/data-intensive-patterns/SKILL.md +204 -0
- package/data-intensive-patterns/assets/example_asset.txt +1 -0
- package/data-intensive-patterns/references/api_reference.md +34 -0
- package/data-intensive-patterns/references/patterns-catalog.md +551 -0
- package/data-intensive-patterns/references/review-checklist.md +193 -0
- package/data-intensive-patterns/scripts/example.py +1 -0
- package/data-pipelines/SKILL.md +252 -0
- package/data-pipelines/assets/example_asset.txt +1 -0
- package/data-pipelines/references/api_reference.md +301 -0
- package/data-pipelines/references/review-checklist.md +181 -0
- package/data-pipelines/scripts/example.py +1 -0
- package/design-patterns/SKILL.md +245 -0
- package/design-patterns/assets/example_asset.txt +1 -0
- package/design-patterns/references/api_reference.md +1 -0
- package/design-patterns/references/patterns-catalog.md +726 -0
- package/design-patterns/references/review-checklist.md +173 -0
- package/design-patterns/scripts/example.py +1 -0
- package/domain-driven-design/SKILL.md +221 -0
- package/domain-driven-design/assets/example_asset.txt +1 -0
- package/domain-driven-design/references/api_reference.md +1 -0
- package/domain-driven-design/references/patterns-catalog.md +545 -0
- package/domain-driven-design/references/review-checklist.md +158 -0
- package/domain-driven-design/scripts/example.py +1 -0
- package/effective-java/SKILL.md +195 -0
- package/effective-java/assets/example_asset.txt +1 -0
- package/effective-java/references/api_reference.md +1 -0
- package/effective-java/references/items-catalog.md +955 -0
- package/effective-java/references/review-checklist.md +216 -0
- package/effective-java/scripts/example.py +1 -0
- package/effective-kotlin/SKILL.md +225 -0
- package/effective-kotlin/assets/example_asset.txt +1 -0
- package/effective-kotlin/references/api_reference.md +1 -0
- package/effective-kotlin/references/practices-catalog.md +1228 -0
- package/effective-kotlin/references/review-checklist.md +126 -0
- package/effective-kotlin/scripts/example.py +1 -0
- package/kotlin-in-action/SKILL.md +251 -0
- package/kotlin-in-action/assets/example_asset.txt +1 -0
- package/kotlin-in-action/references/api_reference.md +1 -0
- package/kotlin-in-action/references/practices-catalog.md +436 -0
- package/kotlin-in-action/references/review-checklist.md +204 -0
- package/kotlin-in-action/scripts/example.py +1 -0
- package/lean-startup/SKILL.md +250 -0
- package/lean-startup/assets/example_asset.txt +1 -0
- package/lean-startup/references/api_reference.md +319 -0
- package/lean-startup/references/review-checklist.md +137 -0
- package/lean-startup/scripts/example.py +1 -0
- package/microservices-patterns/SKILL.md +179 -0
- package/microservices-patterns/references/patterns-catalog.md +391 -0
- package/microservices-patterns/references/review-checklist.md +169 -0
- package/package.json +17 -0
- package/refactoring-ui/SKILL.md +236 -0
- package/refactoring-ui/assets/example_asset.txt +1 -0
- package/refactoring-ui/references/api_reference.md +355 -0
- package/refactoring-ui/references/review-checklist.md +114 -0
- package/refactoring-ui/scripts/example.py +1 -0
- package/storytelling-with-data/SKILL.md +238 -0
- package/storytelling-with-data/assets/example_asset.txt +1 -0
- package/storytelling-with-data/references/api_reference.md +379 -0
- package/storytelling-with-data/references/review-checklist.md +111 -0
- package/storytelling-with-data/scripts/example.py +1 -0
- package/system-design-interview/SKILL.md +213 -0
- package/system-design-interview/assets/example_asset.txt +1 -0
- package/system-design-interview/references/api_reference.md +582 -0
- package/system-design-interview/references/review-checklist.md +201 -0
- package/system-design-interview/scripts/example.py +1 -0
- package/using-asyncio-python/SKILL.md +242 -0
- package/using-asyncio-python/assets/example_asset.txt +1 -0
- package/using-asyncio-python/references/api_reference.md +267 -0
- package/using-asyncio-python/references/review-checklist.md +149 -0
- package/using-asyncio-python/scripts/example.py +1 -0
- package/web-scraping-python/SKILL.md +259 -0
- package/web-scraping-python/assets/example_asset.txt +1 -0
- package/web-scraping-python/references/api_reference.md +393 -0
- package/web-scraping-python/references/review-checklist.md +163 -0
- package/web-scraping-python/scripts/example.py +1 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# Effective Kotlin — Code Review Checklist
|
|
2
|
+
|
|
3
|
+
Systematic checklist for reviewing Kotlin code against the 52 best-practice items
|
|
4
|
+
from *Effective Kotlin* (2nd Edition) by Marcin Moskała.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 1. Safety (Items 1–10)
|
|
9
|
+
|
|
10
|
+
### Mutability & Scope
|
|
11
|
+
- [ ] **Item 1 — Limit mutability** — Are `val` and immutable collections used by default? Is `var` used only when truly necessary? Are mutable collections encapsulated?
|
|
12
|
+
- [ ] **Item 2 — Minimize variable scope** — Are variables declared close to first use? Are any variables declared at function-top that could be scoped tighter? Are `let`/`run` used to restrict scope?
|
|
13
|
+
|
|
14
|
+
### Null Safety & Types
|
|
15
|
+
- [ ] **Item 3 — Eliminate platform types** — At Java/Kotlin boundaries, are types explicitly annotated? Do platform types (`Type!`) leak into Kotlin APIs?
|
|
16
|
+
- [ ] **Item 4 — No exposed inferred types** — Do public functions and properties declare explicit types? Could an implementation change silently alter the public type?
|
|
17
|
+
|
|
18
|
+
### Preconditions & Error Handling
|
|
19
|
+
- [ ] **Item 5 — Specify expectations** — Are `require()` and `check()` used at function entry points? Are preconditions documented for public functions?
|
|
20
|
+
- [ ] **Item 6 — Standard errors** — Are standard exceptions (IllegalArgumentException, IllegalStateException) used instead of custom exceptions for common conditions?
|
|
21
|
+
- [ ] **Item 7 — Null or Failure for expected outcomes** — Do functions that can legitimately fail return `null` or `Result` instead of throwing? Are exceptions reserved for programming errors?
|
|
22
|
+
- [ ] **Item 8 — Proper null handling** — Is `!!` absent or justified? Are safe calls (`?.`), Elvis (`?:`), and smart casts used consistently? No unnecessary null checks?
|
|
23
|
+
|
|
24
|
+
### Resources & Testing
|
|
25
|
+
- [ ] **Item 9 — Resources with use()** — Are all Closeable/AutoCloseable resources wrapped with `use()`? Are file reads using `useLines()` or `use()`?
|
|
26
|
+
- [ ] **Item 10 — Unit tests** — Is business logic covered by tests? Are edge cases and error paths tested? Are tests independent and descriptive?
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 2. Readability (Items 11–18)
|
|
31
|
+
|
|
32
|
+
- [ ] **Item 11 — Design for readability** — Is the code clear on first read? Are there unnecessarily clever constructions? Are complex expressions broken into named intermediate variables?
|
|
33
|
+
- [ ] **Item 12 — Operator meaning consistent** — Do operator overloads match their conventional function names (`plus`, `times`, `contains`)? No surprising operator semantics?
|
|
34
|
+
- [ ] **Item 13 — No Unit? returns** — Does any function return `Unit?`? Is `Unit?` used in conditional logic? Replace with Boolean or sealed type.
|
|
35
|
+
- [ ] **Item 14 — Types specified when unclear** — Are inferred types obvious from context? Do public APIs have explicit type annotations? Would a reader need to navigate to a function to understand the type?
|
|
36
|
+
- [ ] **Item 15 — Explicit receivers** — In nested scope functions or DSLs, are receivers referenced explicitly when ambiguous? Is `@DslMarker` used for DSL scope control?
|
|
37
|
+
- [ ] **Item 16 — Properties represent state** — Do custom getters perform only cheap, side-effect-free, idempotent computations? Is behavior in functions, not properties?
|
|
38
|
+
- [ ] **Item 17 — Named arguments** — Are boolean parameters named? Are same-typed parameters named? Are configuration-style calls using named arguments?
|
|
39
|
+
- [ ] **Item 18 — Coding conventions** — Does the code follow Kotlin coding conventions? Are naming, formatting, and structure consistent? Is ktlint/detekt configured?
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## 3. Reusability (Items 19–25)
|
|
44
|
+
|
|
45
|
+
- [ ] **Item 19 — No repeated knowledge** — Is any business rule, validation, or algorithm defined in more than one place? Is there a single source of truth for each concept?
|
|
46
|
+
- [ ] **Item 20 — stdlib used** — Are standard library functions used instead of hand-rolled equivalents? Check: collection operations, string building, scope functions.
|
|
47
|
+
- [ ] **Item 21 — Property delegation** — Are there repeated property patterns (lazy init, change notification, validation) that should use `by lazy`, `Delegates.observable`, or custom delegates?
|
|
48
|
+
- [ ] **Item 22 — Generics for algorithms** — Are utility functions generic where possible? Is there type-specific duplication that could be parameterized?
|
|
49
|
+
- [ ] **Item 23 — No shadowed type parameters** — In generic classes, do member functions avoid redeclaring the class's type parameter with the same name?
|
|
50
|
+
- [ ] **Item 24 — Variance considered** — Are `out`/`in` modifiers applied to type parameters that are only produced or consumed? Could variance allow more flexible subtype usage?
|
|
51
|
+
- [ ] **Item 25 — Multiplatform reuse** — If targeting multiple platforms, is platform-independent logic in common modules? Are `expect`/`actual` declarations used appropriately?
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 4. Abstraction Design (Items 26–32)
|
|
56
|
+
|
|
57
|
+
- [ ] **Item 26 — Single level of abstraction** — Does each function operate at one consistent level of detail? Are there functions mixing high-level orchestration with low-level manipulation?
|
|
58
|
+
- [ ] **Item 27 — Abstraction protects against changes** — Are external dependencies wrapped behind interfaces? Can implementations be swapped without changing business logic?
|
|
59
|
+
- [ ] **Item 28 — API stability specified** — Are experimental APIs annotated with `@RequiresOptIn`? Are deprecated elements marked with `@Deprecated` with `ReplaceWith`?
|
|
60
|
+
- [ ] **Item 29 — External APIs wrapped** — Are third-party libraries accessed through your own abstractions? Can they be mocked in tests?
|
|
61
|
+
- [ ] **Item 30 — Minimal visibility** — Is `private` the default? Are `internal` and `public` used only when needed? Do properties have restricted setters where appropriate?
|
|
62
|
+
- [ ] **Item 31 — Contracts documented** — Do public APIs have KDoc? Are parameters, return values, exceptions, and edge cases documented?
|
|
63
|
+
- [ ] **Item 32 — Contracts respected** — Do implementations honor the contracts of interfaces they implement? Are `equals`/`hashCode`/`compareTo` contracts maintained?
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 5. Object Creation (Items 33–35)
|
|
68
|
+
|
|
69
|
+
- [ ] **Item 33 — Factory functions considered** — Where constructors are limiting, are factory functions used? Are there complex constructors that would benefit from named factories?
|
|
70
|
+
- [ ] **Item 34 — Primary constructor with defaults** — Are Kotlin primary constructors with default values used instead of Java-style builders or telescoping constructors?
|
|
71
|
+
- [ ] **Item 35 — DSL for complex creation** — For hierarchical or complex object assembly, is a type-safe builder DSL used? Is `@DslMarker` applied?
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## 6. Class Design (Items 36–44)
|
|
76
|
+
|
|
77
|
+
### Composition & Data
|
|
78
|
+
- [ ] **Item 36 — Composition over inheritance** — Is inheritance used only for IS-A relationships? Is Kotlin's `by` delegation used for code reuse? Are there fragile base class issues?
|
|
79
|
+
- [ ] **Item 37 — Data modifier** — Are data-holding classes using the `data` modifier? Are generated methods (equals, hashCode, copy, toString) appropriate?
|
|
80
|
+
- [ ] **Item 38 — Function types for single-method interfaces** — Are single-method interfaces replaced with function types `(A) -> B` or `fun interface`? Is SAM conversion used for Java interop?
|
|
81
|
+
|
|
82
|
+
### Hierarchies & Contracts
|
|
83
|
+
- [ ] **Item 39 — Sealed hierarchies over tagged classes** — Are there classes with type enums and conditional logic that should be sealed class hierarchies? Do `when` blocks benefit from exhaustiveness?
|
|
84
|
+
- [ ] **Item 40 — equals contract** — Is `equals` reflexive, symmetric, transitive, and consistent? Is it overridden together with `hashCode`? Does inheritance break symmetry?
|
|
85
|
+
- [ ] **Item 41 — hashCode contract** — Is `hashCode` consistent with `equals`? Are the same properties used in both? Are mutable objects used as hash keys?
|
|
86
|
+
- [ ] **Item 42 — compareTo contract** — Is `compareTo` antisymmetric, transitive, and consistent with equals? Is `compareBy`/`compareValuesBy` used for clean implementation?
|
|
87
|
+
|
|
88
|
+
### Extensions
|
|
89
|
+
- [ ] **Item 43 — Non-essential API in extensions** — Are classes bloated with utility methods that could be extensions? Could non-essential methods be extracted to improve core API focus?
|
|
90
|
+
- [ ] **Item 44 — No member extensions** — Are extension functions defined at top-level or locally, not as class members? Member extensions are confusing and limited.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## 7. Efficiency (Items 45–52)
|
|
95
|
+
|
|
96
|
+
### Object Creation & Inline
|
|
97
|
+
- [ ] **Item 45 — No unnecessary objects** — In hot paths: are Regex instances cached? Are strings concatenated with StringBuilder? Are primitives used instead of nullable/boxed types?
|
|
98
|
+
- [ ] **Item 46 — Inline for lambdas** — Are frequently-called higher-order functions marked `inline`? Is `noinline` used for stored lambdas? Is `reified` used where runtime type info is needed?
|
|
99
|
+
- [ ] **Item 47 — Inline value classes** — Are domain primitives (IDs, quantities, validated strings) using `@JvmInline value class` to avoid allocation? Are boxing scenarios understood?
|
|
100
|
+
- [ ] **Item 48 — Obsolete references eliminated** — Are unneeded references nulled out? Are caches bounded? Are listeners/callbacks properly unregistered? Are closure captures reviewed?
|
|
101
|
+
|
|
102
|
+
### Collection Processing
|
|
103
|
+
- [ ] **Item 49 — Sequence for multi-step processing** — For large collections with 2+ chained operations, is `.asSequence()` used? Are intermediate collections avoided?
|
|
104
|
+
- [ ] **Item 50 — Operations limited** — Is `any {}` used instead of `filter {}.isNotEmpty()`? Is `count {}` used instead of `filter {}.count()`? Is `maxByOrNull` used instead of `sortedBy {}.last()`?
|
|
105
|
+
- [ ] **Item 51 — Primitive arrays** — For numeric-heavy processing, are `IntArray`/`LongArray`/`DoubleArray` used instead of `List<Int>`/`Array<Int>`?
|
|
106
|
+
- [ ] **Item 52 — Mutable collections where needed** — In local scope hot paths, are mutable collections used for accumulation instead of repeated immutable concatenation? Is mutability kept local?
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Quick Review Workflow
|
|
111
|
+
|
|
112
|
+
1. **Safety first** — Scan for `!!`, `var`, unclosed resources, missing preconditions, platform types
|
|
113
|
+
2. **Readability pass** — Check for clarity, naming, operator usage, coding conventions
|
|
114
|
+
3. **Design assessment** — Evaluate abstraction levels, duplication, visibility, inheritance vs composition
|
|
115
|
+
4. **Kotlin idiom check** — Are Kotlin features (data class, sealed class, extension functions, scope functions, delegation) used appropriately?
|
|
116
|
+
5. **Efficiency review** — For hot paths only: check collection processing, object creation, inline opportunities
|
|
117
|
+
6. **Prioritize findings** — Rank by severity: safety > correctness > readability > design > efficiency
|
|
118
|
+
|
|
119
|
+
## Severity Levels
|
|
120
|
+
|
|
121
|
+
| Severity | Description | Example |
|
|
122
|
+
|----------|-------------|---------|
|
|
123
|
+
| **Critical** | Safety issues, potential crashes, data corruption | `!!` on user input, leaked resources, broken equals/hashCode, mutable shared state without synchronization |
|
|
124
|
+
| **High** | Incorrect Kotlin usage, missed null safety, design violations | Platform types leaking, inheritance abuse, throwing on expected failures, no precondition checks |
|
|
125
|
+
| **Medium** | Non-idiomatic code, missed Kotlin features, readability issues | Java-style builders, manual loops instead of stdlib, tagged classes, no named arguments for booleans |
|
|
126
|
+
| **Low** | Polish, minor optimizations, style improvements | Missing KDoc, Sequence opportunity, inline value class opportunity, convention inconsistencies |
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kotlin-in-action
|
|
3
|
+
description: >
|
|
4
|
+
Apply Kotlin In Action practices (Elizarov, Isakova, Aigner, Jemerov, 2nd Ed).
|
|
5
|
+
Covers Basics (Ch 1-3: functions, extensions, default args), Classes (Ch 4: sealed,
|
|
6
|
+
data, delegation, companion objects), Lambdas (Ch 5-6: functional APIs, sequences,
|
|
7
|
+
scope functions), Nullability (Ch 7-8: safe calls, Elvis, platform types, primitives),
|
|
8
|
+
Conventions (Ch 9: operators, delegated properties), Higher-Order (Ch 10: inline,
|
|
9
|
+
noinline, crossinline), Generics (Ch 11: variance, reified), Reflection (Ch 12:
|
|
10
|
+
KClass, KProperty), DSLs (Ch 13: receivers, @DslMarker), Coroutines (Ch 14:
|
|
11
|
+
structured concurrency, dispatchers, cancellation), Flows (Ch 15: operators,
|
|
12
|
+
StateFlow, SharedFlow). Trigger on "Kotlin In Action", "Kotlin idiom", "Kotlin
|
|
13
|
+
coroutine", "Kotlin flow", "Kotlin DSL", "Kotlin generics", "Kotlin null safety",
|
|
14
|
+
"Kotlin delegation", "Kotlin inline", or "Kotlin extension".
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# Kotlin In Action Skill
|
|
18
|
+
|
|
19
|
+
You are an expert Kotlin developer grounded in the 15 chapters from
|
|
20
|
+
*Kotlin In Action* (2nd Edition) by Roman Elizarov, Svetlana Isakova, Sebastian Aigner,
|
|
21
|
+
and Dmitry Jemerov. You help developers in two modes:
|
|
22
|
+
|
|
23
|
+
1. **Code Generation** — Write idiomatic, safe, and modern Kotlin code
|
|
24
|
+
2. **Code Review** — Analyze existing Kotlin code against the book's practices and recommend improvements
|
|
25
|
+
|
|
26
|
+
## How to Decide Which Mode
|
|
27
|
+
|
|
28
|
+
- If the user asks you to *build*, *create*, *generate*, *implement*, *write*, or *refactor* Kotlin code → **Code Generation**
|
|
29
|
+
- If the user asks you to *review*, *check*, *improve*, *audit*, *critique*, or *analyze* Kotlin code → **Code Review**
|
|
30
|
+
- If ambiguous, ask briefly which mode they'd prefer
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Mode 1: Code Generation
|
|
35
|
+
|
|
36
|
+
When generating Kotlin code, follow this decision flow:
|
|
37
|
+
|
|
38
|
+
### Step 1 — Understand the Requirements
|
|
39
|
+
|
|
40
|
+
Ask (or infer from context):
|
|
41
|
+
|
|
42
|
+
- **What domain?** — Data model, API, concurrency, DSL, UI, server-side?
|
|
43
|
+
- **What platform?** — Kotlin/JVM, Android, Kotlin Multiplatform, server-side?
|
|
44
|
+
- **What quality attributes?** — Safety, readability, concurrency, performance, extensibility?
|
|
45
|
+
|
|
46
|
+
### Step 2 — Apply the Right Practices
|
|
47
|
+
|
|
48
|
+
Read `references/practices-catalog.md` for the full chapter-by-chapter catalog. Quick decision guide by concern:
|
|
49
|
+
|
|
50
|
+
| Concern | Chapters to Apply |
|
|
51
|
+
|---------|-------------------|
|
|
52
|
+
| Functions, named/default args, extensions | Ch 2-3: Expression-body functions, default params, extension functions, top-level functions, local functions |
|
|
53
|
+
| Class hierarchies and OOP design | Ch 4: Sealed classes/interfaces, data classes, class delegation (by), companion objects, visibility modifiers, final by default |
|
|
54
|
+
| Lambda expressions and functional style | Ch 5-6: Lambda syntax, member references, filter/map/flatMap/groupBy, Sequence for lazy evaluation, SAM conversion, scope functions (with/apply/also) |
|
|
55
|
+
| Null safety and type system | Ch 7-8: Nullable types, safe call (?.), Elvis (?:), safe cast (as?), let for null checks, lateinit, platform types, primitive types, Unit/Nothing/Any |
|
|
56
|
+
| Operator overloading and conventions | Ch 9: Arithmetic/comparison operators, get/set/in/rangeTo conventions, destructuring (componentN), delegated properties (by lazy, Delegates.observable, map storage) |
|
|
57
|
+
| Higher-order functions and inline | Ch 10: Function types, inline functions, noinline/crossinline, reified type parameters, non-local returns, anonymous functions |
|
|
58
|
+
| Generics and variance | Ch 11: Type parameters, upper bounds, reified types, covariance (out), contravariance (in), star projection, type erasure |
|
|
59
|
+
| Annotations and reflection | Ch 12: Custom annotations, annotation targets, meta-annotations, KClass, KCallable, KFunction, KProperty |
|
|
60
|
+
| DSL construction | Ch 13: Lambdas with receivers, @DslMarker, invoke convention, type-safe builders |
|
|
61
|
+
| Coroutines and structured concurrency | Ch 14: suspend functions, launch/async/runBlocking, CoroutineScope, dispatchers, cancellation, exception handling, shared mutable state |
|
|
62
|
+
| Reactive streams with Flow | Ch 15: flow{} builder, flow operators (map/filter/transform), terminal operators (collect/toList/reduce), flowOn, buffering, StateFlow, SharedFlow |
|
|
63
|
+
|
|
64
|
+
### Step 3 — Follow Kotlin Idioms
|
|
65
|
+
|
|
66
|
+
Every code generation should honor these principles:
|
|
67
|
+
|
|
68
|
+
1. **val over var** — Immutable by default; use var only when mutation is necessary
|
|
69
|
+
2. **Null safety via the type system** — Non-null types by default; use `Type?` only when nullability is meaningful
|
|
70
|
+
3. **Expression-oriented style** — Use when, try, if as expressions; prefer expression-body functions for simple returns
|
|
71
|
+
4. **Extension functions for API enrichment** — Add behavior to existing types without inheritance
|
|
72
|
+
5. **Sealed hierarchies for restricted types** — Use sealed class/interface instead of type enums with when exhaustiveness
|
|
73
|
+
6. **Data classes for value types** — Automatic equals/hashCode/copy/toString for data holders
|
|
74
|
+
7. **Delegation over inheritance** — Use `by` keyword for interface delegation; `by lazy` for lazy initialization
|
|
75
|
+
8. **Scope functions idiomatically** — `apply` for object configuration, `let` for null-safe transformations, `also` for side effects, `with` for grouping calls, `run` for scoped computation
|
|
76
|
+
9. **Structured concurrency** — Always use CoroutineScope; never use GlobalScope; handle cancellation properly
|
|
77
|
+
10. **Sequences for large collections** — Use `.asSequence()` for multi-step collection pipelines on large data
|
|
78
|
+
|
|
79
|
+
### Step 4 — Generate the Code
|
|
80
|
+
|
|
81
|
+
Follow these guidelines:
|
|
82
|
+
|
|
83
|
+
- **Idiomatic Kotlin** — Use Kotlin features naturally: data classes, sealed hierarchies, extension functions, scope functions, destructuring, delegation, coroutines
|
|
84
|
+
- **Safe by default** — Non-null types, require/check for preconditions, use() for resources, proper error handling with Result or nullable returns
|
|
85
|
+
- **Readable** — Clear naming, named arguments for ambiguous params, expression-body functions, respect coding conventions
|
|
86
|
+
- **Concurrent where needed** — Structured concurrency with coroutines, Flow for reactive streams, proper dispatcher usage
|
|
87
|
+
- **Well-structured** — Small focused functions, clear API boundaries, minimal visibility, documented contracts
|
|
88
|
+
|
|
89
|
+
When generating code, produce:
|
|
90
|
+
|
|
91
|
+
1. **Practice identification** — Which chapters/concepts apply and why
|
|
92
|
+
2. **Interface/contract definitions** — The abstractions
|
|
93
|
+
3. **Implementation** — Idiomatic Kotlin code
|
|
94
|
+
4. **Usage example** — How client code uses it
|
|
95
|
+
5. **Extension points** — How the design accommodates change
|
|
96
|
+
|
|
97
|
+
### Code Generation Examples
|
|
98
|
+
|
|
99
|
+
**Example 1 — Safe Data Model with Sealed Hierarchy:**
|
|
100
|
+
```
|
|
101
|
+
User: "Create a payment processing result type"
|
|
102
|
+
|
|
103
|
+
Apply: Ch 4 (sealed classes, data classes), Ch 7 (null safety), Ch 8 (type system)
|
|
104
|
+
|
|
105
|
+
Generate:
|
|
106
|
+
- Sealed interface PaymentResult with Success, Declined, Error subtypes
|
|
107
|
+
- Data class for each with relevant properties
|
|
108
|
+
- Extension functions for common result handling
|
|
109
|
+
- Exhaustive when expressions for processing
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Example 2 — Coroutine-Based Repository:**
|
|
113
|
+
```
|
|
114
|
+
User: "Create a repository that fetches user data concurrently"
|
|
115
|
+
|
|
116
|
+
Apply: Ch 14 (coroutines, structured concurrency), Ch 10 (higher-order functions),
|
|
117
|
+
Ch 4 (interfaces), Ch 7 (null safety)
|
|
118
|
+
|
|
119
|
+
Generate:
|
|
120
|
+
- UserRepository interface with suspend functions
|
|
121
|
+
- Implementation using coroutineScope + async for parallel fetches
|
|
122
|
+
- Proper dispatcher usage (Dispatchers.IO for network)
|
|
123
|
+
- Cancellation-safe resource handling
|
|
124
|
+
- Error handling with Result type
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Example 3 — Type-Safe DSL Builder:**
|
|
128
|
+
```
|
|
129
|
+
User: "Create a configuration DSL for server setup"
|
|
130
|
+
|
|
131
|
+
Apply: Ch 13 (DSL construction, @DslMarker, invoke convention),
|
|
132
|
+
Ch 5 (lambdas with receivers), Ch 10 (inline functions)
|
|
133
|
+
|
|
134
|
+
Generate:
|
|
135
|
+
- @DslMarker annotation for scope control
|
|
136
|
+
- Inline builder functions with receiver lambdas
|
|
137
|
+
- Nested configuration blocks with type safety
|
|
138
|
+
- Extension functions for DSL enrichment
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Example 4 — Flow-Based Data Pipeline:**
|
|
142
|
+
```
|
|
143
|
+
User: "Create a reactive data pipeline for sensor readings"
|
|
144
|
+
|
|
145
|
+
Apply: Ch 15 (Flow, operators, StateFlow), Ch 14 (coroutines),
|
|
146
|
+
Ch 9 (operator overloading for domain types)
|
|
147
|
+
|
|
148
|
+
Generate:
|
|
149
|
+
- Flow-based sensor data stream
|
|
150
|
+
- Operator pipeline (map, filter, conflate, debounce)
|
|
151
|
+
- StateFlow for latest-value semantics
|
|
152
|
+
- flowOn for dispatcher control
|
|
153
|
+
- Proper exception handling with catch operator
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Mode 2: Code Review
|
|
159
|
+
|
|
160
|
+
When reviewing Kotlin code, read `references/review-checklist.md` for the full checklist.
|
|
161
|
+
|
|
162
|
+
### Review Process
|
|
163
|
+
|
|
164
|
+
1. **Basics scan** — Check Ch 2-3: function style, variable declarations, extension usage, string templates, collection APIs
|
|
165
|
+
2. **Class design scan** — Check Ch 4: sealed vs open, data classes, delegation, visibility, companion objects
|
|
166
|
+
3. **Lambda & collection scan** — Check Ch 5-6: lambda idioms, functional APIs, Sequence usage, scope functions
|
|
167
|
+
4. **Null safety scan** — Check Ch 7-8: nullable type handling, platform types, safe calls, Elvis, type usage
|
|
168
|
+
5. **Convention scan** — Check Ch 9: operator overloading correctness, destructuring, delegated properties
|
|
169
|
+
6. **Advanced scan** — Check Ch 10-13: inline usage, generics, variance, DSL patterns, annotation usage
|
|
170
|
+
7. **Concurrency scan** — Check Ch 14-15: coroutine structure, Flow usage, dispatcher choices, cancellation handling
|
|
171
|
+
|
|
172
|
+
### Review Output Format
|
|
173
|
+
|
|
174
|
+
Structure your review as:
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
## Summary
|
|
178
|
+
One paragraph: overall code quality, Kotlin idiom adherence, main concerns.
|
|
179
|
+
|
|
180
|
+
## Basics & Style Issues
|
|
181
|
+
For each issue found (Ch 2-3):
|
|
182
|
+
- **Topic**: chapter and concept
|
|
183
|
+
- **Location**: where in the code
|
|
184
|
+
- **Problem**: what's wrong
|
|
185
|
+
- **Fix**: recommended change with code snippet
|
|
186
|
+
|
|
187
|
+
## Class Design Issues
|
|
188
|
+
For each issue found (Ch 4):
|
|
189
|
+
- Same structure as above
|
|
190
|
+
|
|
191
|
+
## Lambda & Collection Issues
|
|
192
|
+
For each issue found (Ch 5-6):
|
|
193
|
+
- Same structure as above
|
|
194
|
+
|
|
195
|
+
## Null Safety & Type Issues
|
|
196
|
+
For each issue found (Ch 7-8):
|
|
197
|
+
- Same structure as above
|
|
198
|
+
|
|
199
|
+
## Convention & Delegation Issues
|
|
200
|
+
For each issue found (Ch 9):
|
|
201
|
+
- Same structure as above
|
|
202
|
+
|
|
203
|
+
## Advanced Feature Issues
|
|
204
|
+
For each issue found (Ch 10-13):
|
|
205
|
+
- Same structure as above
|
|
206
|
+
|
|
207
|
+
## Concurrency Issues
|
|
208
|
+
For each issue found (Ch 14-15):
|
|
209
|
+
- Same structure as above
|
|
210
|
+
|
|
211
|
+
## Recommendations
|
|
212
|
+
Priority-ordered list from most critical to nice-to-have.
|
|
213
|
+
Each recommendation references the specific chapter/concept.
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Common Kotlin Anti-Patterns to Flag
|
|
217
|
+
|
|
218
|
+
- **Java-style getters/setters** → Ch 2: Use Kotlin properties with custom accessors
|
|
219
|
+
- **Java-style static utility classes** → Ch 3: Use top-level functions and extension functions
|
|
220
|
+
- **Explicit type where inference is clear** → Ch 2: Let the compiler infer local variable types
|
|
221
|
+
- **Missing default parameter values** → Ch 3: Use default params instead of overloads
|
|
222
|
+
- **Inheritance for code reuse** → Ch 4: Use class delegation with `by` keyword
|
|
223
|
+
- **Open classes by default** → Ch 4: Kotlin classes are final by default; keep them final unless designed for inheritance
|
|
224
|
+
- **Type enum + when** → Ch 4: Replace with sealed class hierarchy
|
|
225
|
+
- **Mutable data holders** → Ch 4: Use data class with val properties and copy()
|
|
226
|
+
- **Nullable everything** → Ch 7: Use non-null types by default; nullable only when absence is meaningful
|
|
227
|
+
- **Force-unwrapping (!!)** → Ch 7: Use safe calls (?.), Elvis (?:), let, or lateinit
|
|
228
|
+
- **Ignoring platform types** → Ch 7: Add explicit nullability at Java boundaries
|
|
229
|
+
- **Manual loops for transforms** → Ch 5-6: Use filter/map/flatMap/groupBy/fold
|
|
230
|
+
- **Eager processing of large collections** → Ch 5-6: Use Sequence for multi-step pipelines
|
|
231
|
+
- **Lambda instead of member reference** → Ch 5: Use `::functionName` where clearer
|
|
232
|
+
- **Missing named arguments** → Ch 3: Name boolean and same-typed parameters
|
|
233
|
+
- **Boxed primitives in hot paths** → Ch 8: Use IntArray/LongArray/DoubleArray instead of List<Int>
|
|
234
|
+
- **GlobalScope usage** → Ch 14: Use structured concurrency with proper CoroutineScope
|
|
235
|
+
- **Blocking in coroutines** → Ch 14: Use withContext(Dispatchers.IO) for blocking calls
|
|
236
|
+
- **Uncancellable coroutines** → Ch 14: Ensure cooperative cancellation with isActive/ensureActive
|
|
237
|
+
- **Cold Flow collected multiple times** → Ch 15: Use SharedFlow/StateFlow for hot streams
|
|
238
|
+
- **Missing flowOn for dispatcher** → Ch 15: Use flowOn to control upstream execution context
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## General Guidelines
|
|
243
|
+
|
|
244
|
+
- **Idiomatic Kotlin > Java-in-Kotlin** — Use Kotlin features (data classes, sealed hierarchies, extensions, scope functions, delegation, coroutines, flows) naturally. Don't write Java with Kotlin syntax.
|
|
245
|
+
- **Safety first** — Kotlin's type system prevents many bugs. Use it fully: non-null by default, sealed hierarchies for state, require/check for contracts.
|
|
246
|
+
- **Readability is king** — Code is read far more than written. Prefer clarity over cleverness.
|
|
247
|
+
- **Structured concurrency always** — Never launch coroutines without a proper scope. Handle cancellation and exceptions.
|
|
248
|
+
- **Know the stdlib** — The standard library is rich. Before writing utilities, check if a stdlib function already exists.
|
|
249
|
+
- **Efficiency where it matters** — Don't optimize prematurely, but know the tools: Sequence, inline, primitive arrays, Flow operators.
|
|
250
|
+
- For deeper practice details, read `references/practices-catalog.md` before generating code.
|
|
251
|
+
- For review checklists, read `references/review-checklist.md` before reviewing code.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|