---
title: "Discussion on \"Code Smell 46 - Repeated Code\" | Hashnode"
description: "Discussion on \"Code Smell 46 - Repeated Code\". DRY is our mantra. Teachers tell us to remove duplication. We need to go beyond.\nProblems\n\nCode Duplication\n\nMaintainability\n\nDon't Repeat Yourself\n\n\nSolutions\n\nFind repeated patterns (not repeated code).\n\nCreate an abstraction.\n\nParametrize abstract..."
url: "https://hashnode.com/posts/code-smell-46-repeated-code/5fcefccdded61e1bd07e93f1"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Code Smell 46 - Repeated Code](https://maximilianocontieri.com/code-smell-46-repeated-code?utm_source=hashnode&utm_medium=feed)

DRY is our mantra. Teachers tell us to remove duplication. We need to go beyond. Problems Code Duplication Maintainability Don't Repeat Yourself Solutions Find repeated patterns (not repeated code). Create an abstraction. Parametrize abstract...

Dec 8, 2020 · 2 min read · maximilianocontieri.com  
Updated May 31, 2022  
Read the article

-   [#programming](https://hashnode.com/tag/programming)
-   [#2articles1week](https://hashnode.com/tag/2articles1week)
-   [#software-development](https://hashnode.com/tag/software-development)
-   [#web-development](https://hashnode.com/tag/web-development)
-   [#object-oriented-programming](https://hashnode.com/tag/object-oriented-programming)

## Written by

[Maxi Contieri](https://hashnode.com/@mcsee)

@mcsee · Buenos Aires

  
[View profile](https://hashnode.com/@mcsee)

Software Engineer

I’m a senior software engineer loving clean code, and declarative designs. S.O.L.I.D. and agile methodologies fan.

## Responses 1

Markdown supported · ⌘↵ to post

[BarTech](https://hashnode.com/@bartech)

[Dec 8, 2020](https://hashnode.com/posts/code-smell-46-repeated-code/5fcefccdded61e1bd07e93f1/comment/5fcfae54a38e1f208d80d940)

Full agreement with general idea. But given example that should fix supposed duplication is a regression from readability perspective. `TextReplacer()->replace()` API is awful. First it's more code not less and most important it's way harder to understand. I would classify this as clever code or overengineering. Refactoring like this make sense when repeated code have more logic, some local variables, in general you have to spend time to understand what it's doing. In this case abstracting and giving method descriptive name make total sense. In your example it's making simple code complicated.

[Maxi Contieri](https://hashnode.com/@mcsee)

[Dec 8, 2020](https://hashnode.com/posts/code-smell-46-repeated-code/5fcefccdded61e1bd07e93f1/comment/5fcfae54a38e1f208d80d940#reply-5fcfdf5a9916522a48417fef)

I agree with you. It is an over engineer example. I tried to find a better one and also shorter. Many examples i find in real world are too long to embed.

I might replace it with a better one soon.
