Code Style
This skill keeps code explicit, linear, and honest about state, failure, ownership, and side effects. Its directives favor enforceable invariants, narrow boundaries, simple abstractions, and sans-I/O decision logic.
Treat each directive as a language-agnostic semantic requirement. Adapt its TypeScript example to the target language's native syntax, type system, resource-management mechanisms, and compiler checks.
Effective Strategies for Clear, Correct Code
Follow the guidelines below. Read each linked reference that applies before writing or reviewing code.
- Express control flow so that the permitted state and successful path are easy to read.
- Use affirmative conditions when a condition needs mental negation to understand.
- Reject invalid or exceptional cases early with guard clauses.
- Make decisions visible at their point of effect instead of concealing valid values or control flow through implicit behavior.
- Reserve conditional expressions for selecting one of two simple values, not for hidden effects.
- Make valid state explicit and enforce it throughout the system.
- Keep failure, ownership, and information at their decision-owning boundaries.
- Handle and record each failure once at a narrow error boundary, preserving unrelated errors and their original causes.
- Bind resource ownership to lifetime so a resource never escapes uninitialized or unreleased.
- Preserve caller-relevant information when normalizing external data so continuation, retry, filtering, fallback, and other policy choices remain with the caller.
- Let consumers control continuation and stopping through lazy pagination.
- Keep abstractions and public contracts intentional.
- Keep one-off or cosmetic indirection out of the design with simple abstractions.
- Convert untrusted external payloads into trusted values at the first controlled boundary.
- Keep required absence explicit and reject fabricated defaults unless the domain defines the exact value.
- Keep consumer APIs intentional and side-effect-free with narrow public surfaces.
- Put decisions in a pure core and keep I/O in the imperative shell.