Refactoring at scale¶
Refactoring a large codebase fails for a predictable reason: you change something without knowing everything that depends on it. Understand's job in a big refactor is to make the blast radius visible before you touch code, and to prove afterward that the change actually improved things. This page sequences the how-tos into a safe workflow.
1. Pick the right targets¶
Don't refactor by intuition. Let the data point at the worst offenders:
- Where is my risky / complex code? — the most complex and largest units usually give the best return on a refactor.
- Find unused / dead code — deleting is the cheapest refactor; remove what nothing calls before restructuring the rest.
2. Understand the blast radius¶
Before changing an entity, learn who depends on it. This is where Understand earns its keep:
- The Information Browser lists every place an entity is used and everything that calls it — expand Called By to see the full reach.
- A call or dependency graph shows the same reach visually, so you can spot the seams where a change is contained versus where it ripples.
- For file- and subsystem-level impact, use dependencies.
3. Refactor safely¶
For the mechanical edits, Understand's editor provides refactorings that use the parsed model rather than text matching — Rename, Inline, and Extract — so a rename updates real references, not same-named strings. See Refactor safely.
4. Lock in the new structure¶
A refactor that isn't enforced erodes. Once you've established the intended structure, make violating it fail:
- Enforce dependency rules to codify "X must not depend on Y" so the layering you just fixed can't quietly regress. If you don't yet have an architecture describing the intended structure, see What is an architecture & why build one? and Build, browse & enable architectures.
- CodeCheck rules (including complexity limits) can gate the same properties in CI.
5. Prove it improved¶
Close the loop by measuring before and after:
- Compare two versions of a project to see structural differences between the pre- and post-refactor databases.
- Where did the churn happen? (Changes Treemap) shows where change concentrated.
- Export & track metrics over time to confirm complexity and size trended the right way — not just locally, but project-wide.
Refactoring for complexity specifically?
If the whole point is to drive complexity down, see the complexity-focused tour in Finding & reducing complexity.