--- name: code-that-fits-in-your-head description: "Heuristics for the shape of code inside one code base, after Mark Seemann's Code That Fits in Your Head (2021), updated for coding agents: units small enough to hold in mind, invariants in types, APIs hard to misuse, explicit effects. Use when writing or reviewing code, refactoring accidental complexity or a Big Ball of Mud, controlling technical debt in generated code, designing a type, an invariant or an in-code API, decomposing a long function or a tangled module, replacing a method or class side by side (Strangler), reading or measuring an unfamiliar code base, debugging a defect by hypothesis and bisection, setting up a maintainable code base, or turning a recurring finding into a lint or CI gate. Not for choosing, writing or repairing tests, TDD included (pragmatic-verification), choosing a design, state ownership, migration or rollout, or threat modelling (pragmatic-architecture), security audits, production incident response, performance profiling, or language and framework tutorials." --- # Code That Fits in Your Head Heuristics for the shape of code inside one code base, based on Mark Seemann's 2021 book and clearly labelled agent-era amendments: can the next reader, human or agent, hold a unit in mind and change it safely? Code examples are C#-first; every rule and the tooling tables are language-neutral. ## Scope A question belongs to this skill when it is answered by reading the code. | The question is answered by | Use | |-----------------------------|-----| | Reading the code: size, cohesion, coupling, names, types, explicit effects | This skill | | Running something: which checks to write and at which level, whether a test can fail, a flaky or slow test, when a task is done | `pragmatic-verification` | | Replaying a sequence of events: a retry, a crash, two writers, two versions; where state lives; how a schema or contract changes; rollout and rollback; what an untrusted caller can reach | `pragmatic-architecture` | | Thinking before or around the code: which problem to solve, build or buy, a cause outside the code, delivery and operations | `fpf-problem-solving` | The skill prescribes no order of writing tests and code. Test-driven development is a large part of the book; here it is left to `pragmatic-verification`, which treats it as one working technique among others. Two ideas from it stay, because they are about code and not about tests: build a feature as a thin slice from the boundary inward, and treat code that is hard to check as a design smell. ## Philosophy (Why This Skill Exists) Software development is principally a **design activity**, not construction. An agent may produce most of the text, but people still review, operate, extend, and own the resulting system. These heuristics make software sustainable: understandable, resistant to architectural erosion, and cheap to change after thousands of decisions. Core mental model from Chapter 1: | Metaphor | What it gets right | What it misses | |----------|-------------------|-----------------| | **Building a house** | Plans, structure | Software endures; there's no construction phase (compiling is free); dependencies can start anywhere | | **Growing a garden** | Pruning, refactoring, tending | Code does not improve by itself; generated code still needs stewardship | | **Art / craft** | Skill, mastery, situational knowledge | Doesn't scale; leaves newcomers without guidance | | **Engineering** (the target) | Heuristics, review, sign-off, checklists | We're not there yet — physical-construction calculations don't apply | > "The act of describing a program in unambiguous detail and the act of programming are one and the same." — Kevlin Henney **Practical implications for a code agent:** 1. **Successful software endures.** Prefer changes that preserve clear boundaries and keep future change affordable. 2. **Complexity is the enemy, not task size.** Agents can complete changes spanning tens of thousands of lines when architecture, plan, and acceptance criteria are sound. Reject needless coupling, duplication, hidden effects, and unverifiable bulk—not large scope by itself. 3. **Heuristics, not laws.** Understand the purpose of a rule before applying or relaxing it. Project policy overrides generic formatting and workflow conventions. 4. **Executable constraints are part of design.** Types, schemas, architecture checks and lint rules keep a structure true after its author has left, for human- and agent-written code alike. 5. **Code is a liability.** Generated volume is not progress. Prefer the smallest coherent design that solves the problem without accumulating debt. See `references/foundations/` for more on sustainability, readability, and brain-limited design. ## How to Use This Skill 1. Identify the user's task (writing, reviewing, refactoring, debugging, setting up). If it falls outside the Scope table, say which skill covers it and use that one 2. Read `guidelines.md` — it maps tasks and symptoms to specific reference files 3. Load only the reference files relevant to the current task (progressive disclosure) 4. Apply the rules; when in doubt, consult `references/practices-glossary/` for cross-references 5. When a rule proves repeatedly useful in a repository, operationalize it (`workflows/operationalize-finding.md`) so it persists as a gate and in project agent instructions. ## Chapter Index | Topic | Use when... | |-------|-------------| | `references/foundations/` | Sustainability, readability, complexity control, and code as liability | | `references/codebase-setup/` | Starting or inheriting a code base — git, build automation, warnings-as-errors | | `references/encapsulation/` | Designing types with invariants; DTO vs Domain Model, always-valid, Postel's law, parse-don't-validate | | `references/decomposition/` | Controlling method and system complexity; cyclomatic complexity, cohesion, coupling, feature envy, fractal architecture | | `references/api-design/` | Designing a public API; affordance, poka-yoke, CQS, hierarchy of communication, naming over comments | | `references/separation-of-concerns/` | Adding cross-cutting concerns; Decorator pattern, logging, what to log, performance vs legibility | | `references/teamwork-git/` | Writing commits, reviewing changes, continuous integration, collective ownership | | `references/evolution/` | Changing code that other code depends on; Strangler at method and class level, temporary paths and their removal, versioning, deprecation, regular dependency updates | | `references/troubleshooting/` | Debugging a defect; scientific method, rubber ducking, reproduce-as-test, bisection, non-deterministic defects | | `references/code-navigation/` | Onboarding to a code base; big picture, file organisation, cycles, tests as documentation, behavioural code analysis | | `references/tooling/` | Executable measurement commands: complexity, cycles, duplication, dead code, hotspots, architecture tests | | `references/practices-glossary/` | Looking up a named book practice and its current status | ### ⚠️ Editorial amendments (NOT from the book) The folder below is NOT content from Seemann's book. It contains our own additions covering agent-specific concerns the 2021 book does not address. Do not attribute these files to Seemann. See `references/agent-native/knowledge.md`. | Topic | Use when... | |-------|-------------| | `references/agent-native/` | Hallucinated APIs and dependency grounding, types and schemas as guardrails, and accountable review of agent-authored changes | ## Workflows Composite step-by-step processes live in `workflows/`: | Task | Workflow | |------|----------| | Review a pull request / piece of code | `workflows/review-code.md` | | Add a new feature as a thin slice from the boundary inward | `workflows/add-feature.md` | | Investigate and fix a defect | `workflows/debug-defect.md` | | Turn a recurring finding into an executable gate and persist it in project memory | `workflows/operationalize-finding.md` | See `guidelines.md` for the full routing layer (task → file, symptom → file).