The Code Smells are similar in concept to Development-level Anti-patterns. Sometimes in our code, we introduce code smell unintentionally those makes our design fragile.
Definition of Code smell
Code smell, also known as a bad smell, in computer programming code, refers to any symptom in the source code of a program that possibly indicates a deeper problem.
Martin fowler says:
"a code smell is a surface indication that usually corresponds to a deeper problem in the system"
Code smell creates lot of problems while introducing new feature or maintains the codebase,
Often developer has to write repeatable code, breaking encapsulation, breaking abstraction etc.
If code smells are not corrected.
So always refactor code smell while developing.
In this article, we discuss one of the popular code smell “SHOTGUN SURGERY”
Shotgun surgery says, to introduce a small new change, a developer has to change many classes and methods, most of the time has to write duplicate codes which violate “Don’tRepeatYourself” principle.
Cause of Shotgun surgery smell:
1. Due to poor separation of concern.
2. Fail to understand the responsibility. Often due to misunderstanding (Single responsibility principle)
3. Not identifying the common behavior or behavior with a slight change.
4. Fail to introduce proper design pattern.
Consequences of Shotgun Surgery:
1. Lots of duplicates code
2. Taking more time to develop a small feature.
3. Unmaintainable code base.