Change PreventersHigh

Shotgun Surgery: What It Costs and How to Fix It

A single logical change requires small edits scattered across many different classes or files.

Annual Cost$5k - $40k
Severity
4/5
CategoryChange Preventers
Detection4 tools

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.

Threshold: If a single conceptual change (add a field, change a business rule) requires editing 4+ files, you have Shotgun Surgery. Git commit history showing files that always change together is the most reliable detection method.

Why It Costs Money

1

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.

2

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.

3

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 SizeSmall (<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.

SonarQube
squid:S1200

High coupling between classes indicates scattered responsibilities

CodeClimate
similar-code

Repeated patterns across files suggest shotgun surgery

Git analysis
Co-changed file analysis

Files that always change together in commits indicate shotgun surgery

CodeScene
Change coupling analysis

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

Effort: 2-6 hours
Impact: Localises change to one file instead of many

Inline Class

A class exists only to hold one piece of a scattered concern

Effort: 2-4 hours
Impact: Reduces the number of files that change for a single reason

Extract Class (centralise)

The scattered edits all serve a concept that deserves its own class

Effort: 4-12 hours
Impact: Creates a single point of change for the concept

Related Smells