Shotgun Surgery is a code smell where a single conceptual change to the system requires making small, scattered modifications across many different classes, files, or modules simultaneously — the exact inverse of Divergent Change, indicating that a single cohesive concept is spread across the codebase rather than being localized in one place, so every time that concept must be modified, the developer must hunt down and update all its scattered fragments.
What Is Shotgun Surgery?
The smell manifests when one logical change requires touching many locations:
- Adding a Currency: To support a new currency, the developer must update PaymentProcessor, InvoiceGenerator, ReportExporter, DatabaseSchema, APISerializer, EmailTemplate, and PDFRenderer — 7 separate files for one conceptual addition.
- Changing a Business Rule: "Orders over $500 get free shipping" — the rule lives in OrderService, CheckoutController, ShoppingCartSummary, InvoiceCalculator, and AnalyticsTracker. Change the threshold and update 5 places.
- Adding a Log Field: Adding a correlation_id to application logs requires updating every logging call site — potentially dozens of files.
- Security Patch: A sanitization requirement for user input requires updating every endpoint handler independently rather than one centralized input processing layer.
Why Shotgun Surgery Matters
- Miss Rate Certainty: Studies of real defects consistently find that shotgun surgery changes have the highest miss rate of any change pattern. Developers under time pressure miss locations. The probability of missing at least one site scales exponentially with the number of sites — a change requiring 10 modifications has a very high probability that at least one will be missed or incorrectly applied, immediately creating a bug.
- Change Cost Multiplication: The cost of every future change to a scattered concept scales linearly with the number of locations. A concept in 10 places costs 10x as much to change as a concept in 1 place — over the lifetime of a codebase, this multiplier compounds into massive accumulated maintenance cost.
- Knowledge Requirement: To make a shotgun surgery change correctly, the developer must know all the places that implement the concept. New team members have no way of knowing all locations. Senior developers forget over time. The codebase becomes dependent on tribal knowledge for safe modification.
- Code Freeze Pressure: The complexity and risk of shotgun surgery changes creates pressure to freeze affected areas of the codebase — "It works, don't touch it." This paralysis accelerates technical debt accumulation and reduces the team's ability to respond to business requirements.
- Merge Conflict Amplification: A change touching 15 files is much more likely to conflict with parallel development branches than a change touching 1-2 files, directly reducing development team throughput.
Shotgun Surgery vs. Divergent Change
These two smells are opposite manifestations of the same cohesion problem:
| Smell | Symptom | Meaning |
|-------|---------|---------|
| Shotgun Surgery | One change → many classes | One concept is scattered across many classes |
| Divergent Change | One class → many reasons to change | Many concepts are crammed into one class |
Both indicate violation of the Single Responsibility Principle — either too much spread or too much concentration.
Refactoring: Move Method / Extract Class
The standard fix is consolidating scattered logic into a single location:
1. Identify the concept that requires shotgun surgery changes.
2. Create a new class (or identify the most appropriate existing class) to own that concept entirely.
3. Move all scattered implementations of the concept into that single class.
4. Replace all the scattered call sites with calls to the single consolidated class.
For the currency example: Create a CurrencyRegistry class that is the single source of truth for all currency-related data and logic. Every component that needs currency information asks CurrencyRegistry rather than implementing its own handling.
Tools
- CodeScene: Behavioral analysis identifies "change coupling" — files that are always changed together, exposing shotgun surgery patterns in commit history.
- SonarQube: Module cohesion metrics can surface concepts that are spread across multiple modules.
- git log analysis: Files that consistently appear together in commits signal shotgun surgery — git log --follow -p patterns.
- Structure101: Visual dependency and cohesion analysis.
Shotgun Surgery is scattered logic — the smell that reveals when a single business concept has been distributed across a codebase rather than encapsulated in one location, turning every future enhancement of that concept into a multi-file archaeological expedition with a significant probability of missed sites and introduced bugs.