refactor-codebase-with-types
Refactor Codebase with Types
Surface refactoring opportunities inspired by Alexis King's “Parse, don't validate” and “Types as axioms.” The aim is to move facts learned at runtime into values and types so valid states are easy to construct, invalid states are hard or impossible to represent, and execution code stops re-checking things boundary code already proved.
Glossary
Use these terms exactly in suggestions. Full definitions are in LANGUAGE.md.
- Boundary — where less-structured outside data enters the program.
- Parser — code that consumes less-structured input and produces more-structured output or a typed failure.
- Validator — code that checks a fact but throws away the evidence, often returning
void,(),boolean, or raising. - Evidence — a value/type that preserves a checked fact for later code.
- Precise representation — a datatype that encodes the facts downstream code depends on.
- Illegal state — a value shape the domain or algorithm cannot correctly handle.
- Correct by construction — a representation whose constructors preserve the invariant.
- Partial function — code whose signature promises more than it can deliver for all inputs.
- Burden of proof — the obligation to establish a precondition before execution can proceed.
- Shotgun parsing — validation scattered through processing code.
- Axiom — a constructor or factory that introduces a valid base case.
More from dmmulroy/cf-twitch
tdd
Test-driven development with red-green-refactor loop. Use when user wants to build features or fix bugs using TDD, mentions "red-green-refactor", wants integration tests, or asks for test-first development.
1improve-codebase-architecture
Find deepening opportunities in a codebase, informed by the domain language in CONTEXT.md and the decisions in docs/adr/. Use when the user wants to improve architecture, find refactoring opportunities, consolidate tightly-coupled modules, or make a codebase more testable and AI-navigable.
1