Shotgun Surgery: What It Costs and How to Fix It
A single logical change requires small edits scattered across many different classes or files.
What It Is
Shotgun Surgery is the inverse of Divergent Change. Where Divergent Change means one class changes for many reasons, Shotgun Surgery means one reason causes changes in many classes. For example, adding a new user field requires editing the User model, the database migration, the API controller, the serialiser, the form component, the validation logic, and the test fixtures. Each edit is small, but missing any one creates an inconsistency. The scattered nature of the change makes it easy to forget a location and hard to verify completeness.
Why It Costs Money
Incomplete changes are the primary cost. When a change requires touching 8 files and a developer updates 7, the missed file creates a bug that may not surface until production. These partial-change bugs are expensive because they pass all automated tests for the files that were updated.
Change effort is multiplied. A conceptually simple change (add a field, rename a status) requires opening, understanding, modifying, and testing many files. Developer time scales linearly with the number of scattered edit sites.
Knowledge requirements are unreasonable. The developer making the change must know all the places that need updating. This knowledge is rarely documented and lives in the heads of senior team members, creating a bus factor risk.
Specific Cost Mechanisms
- ●Partial-change bugs: each missed edit site costs 4-12 hours to diagnose and fix after production discovery
- ●Multiplied effort: each scattered change takes 3-5x longer than a localised change
- ●Knowledge dependency: only senior developers who know all the edit sites can safely make changes
Estimated Annual Cost
Cost per instance by team size and codebase size. Based on $120,000 average developer salary. See full methodology.
| Team Size | Small (<50k LOC) | Medium (50k-200k) | Large (200k+) |
|---|---|---|---|
| 3 devs | $5,000 | $12,000 | $24,000 |
| 5 devs | $8,300 | $20,000 | $40,000 |
| 10 devs | $12,500 | $30,000 | $40,000 |
| 20 devs | $16,600 | $40,000 | $40,000 |
How to Detect It
Specific rules and thresholds for automated detection. See full tool comparison.
High coupling between classes indicates scattered responsibilities
Repeated patterns across files suggest shotgun surgery
Files that always change together in commits indicate shotgun surgery
Identifies files with high co-change frequency
Refactoring Patterns
Proven techniques to eliminate this smell. See all refactoring patterns.
Move Method/Field
Behaviour scattered across classes belongs in a single class
Inline Class
A class exists only to hold one piece of a scattered concern
Extract Class (centralise)
The scattered edits all serve a concept that deserves its own class