refactoring-safely

Featured

Change the structure of code that already exists without changing what it does: smells as triggers, the named transformations (extract/inline, move feature, organise data, simplify conditionals), and above all the workflow that makes it safe — characterization tests first, one transformation at a time, green between every step. Use when a file or function is already too large; when asked to "split this module", "extract this", "break up main.py", "clean up this legacy code", "reduce coupling here"; when a shape advisory fires on a grown file; or before any restructuring of code that has users. Do NOT use to decide the target layout of a NEW project (use architecture-first), for unit-level naming and function quality in code you are writing fresh (use code-complexity), for capacity or storage decisions (use system-and-data-design), or to strip over-engineering on request (use lean-code). This is the transformation with a net; deciding WHERE things should end up is a different question, and doing both at once i

AI & Automation 150 stars 24 forks Updated 3 days ago MIT

Install

View on GitHub

Quality Score: 88/100

Stars 20%
73
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Refactoring safely — changing shape without changing behaviour Refactoring is a behaviour-preserving transformation. If behaviour changed, that was not a refactor, it was a rewrite with optimistic branding — and the reason large restructures fail is almost always that the two were done in one step. ## The rule that makes the rest work **Never restructure and change behaviour in the same commit.** Alternate deliberately: refactor (green → green, no behaviour change), then change behaviour (with a new test). When both happen at once, a failing test cannot tell you which half broke it. ## Before touching anything: the net Legacy code is code without tests, regardless of age. So: 1. **Characterization tests first.** Not tests of what it *should* do — tests of what it *does*, including behaviour you consider wrong. Their job is to detect change, not to judge it. Wrong-but-tested behaviour gets fixed later, on purpose, in its own commit. 2. **Cover the seams you are about to cut**, not the whole file. Coverage of the region under the knife is what matters. 3. **Confirm they fail when you break something.** A characterization test that passes against deliberately broken code is worse than none — run that check once. 4. **Know how to revert.** Small commits, one transformation each. ## Smells, and what each one actually indicates | Smell | Underlying problem | Transformation | |---|---|---| | Long function | Several jobs in one scope | Extract function, split by...

Details

Author
AnastasiyaW
Repository
AnastasiyaW/codex-claude-code-config
Created
5 months ago
Last Updated
3 days ago
Language
Python
License
MIT

Bundled in these plugins

Similar Skills

Semantically similar based on skill content — not just same category