guide-complexity
Use when code is written or changed that branches heavily, in any language: if/else or switch chains, type-check cascades, kind fields compared to strings, flag parameters, deep nesting. Produces the
SKILL.mdskills/guides/guide-complexity/SKILL.md
GitHubGuide: complexity
Applies to any code that adds or grows branching: a chain of conditions, a dispatch on a kind, a flag that changes what a function does, nesting past two levels.
Shaping step
- Before writing the branch, name what varies: the kinds, the cases.
- Put each case behind one shape: a table, a map of handlers, a type per kind, one function per flag value.
- Keep each function one level of decision; extract the rest.
- The branching already exists and is to be reworked: run the
complexity-reworkskill.
Ok at merge
- No new chain of more than three conditions on the same value.
- No kind compared to strings in more than one place; no boolean flag parameter.
- Nesting at most two levels in the changed code.