Duplicated Code — Code Smells Catalog Skip to content

Duplicated Code

Also known as: Clones, Code Clone, Duplicate Code, Common Methods in Sibling Class, External Duplication

Dispensables Duplication Code SmellDesign SmellImplementation Smell Within Class

The same logic in five places. Change one, miss another, and watch the behavior quietly diverge. According to Fowler, this is the single worst smell in a codebase.

1 min read 1 source

Overview

Duplicated Code does not need further explanation. According to Fowler, redundant code is one of the worst smells [1]. One thing is that this makes it more challenging to read the program. Checking whether the copies are identical is yet another issue - looking at whether there are for sure no tiny differences between code blocks in search of Oddball Solution further unnecessarily absorbs developer time. Yet another thing is that whenever a change is made, one needs to check if this should have happened to just one or all of the existing copies of code, wherever they are.

Refactoring

  • Extract Class
  • Extract Function
  • Pull Up Method
  • Slide Statement
  • Form Template Method

Sources

Browse All 56 Smells