DRY is our mantra. Teachers tell us to remove duplication. We need to go beyond.
Find repeated patterns (not repeated code).
Create an abstraction.
Parametrize abstraction calls.
Use composition and never inheritance.
Unit test new abstraction.
Linters can find repeated code.
There are not very good finding similar patterns.
Maybe soon machine learning will help us find such abstractions automatically.
For now, it is up to us, humans.
Repeated code is always a smell.
Copying and pasting code is always a shame.
With our refactoring tools, we need to accept the duplication remove challenge trusting our tests as a safety net.
Code Smell 11 - Subclassification for Code Reuse
Maxi Contieri ⭐⭐⭐ ・ Oct 30 '20 ・ 2 min read
Photo by Sid Balachandran on Unsplash
Copy and paste is a design error.
Top comments (0)