From the course: Agile Software Development: Code Quality

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

What is duplication?

What is duplication? - SonarQube Tutorial

From the course: Agile Software Development: Code Quality

Start my 1-month free trial

What is duplication?

- [Instructor] Imagine you need to add a new feature to your application. However, this feature is really similar to a feature that's already implemented. Let's assume that the existing feature is just four lines long. To implement the new feature, you just need line three to behave differently. One way to add the new feature would be to adapt the existing code to support the existing feature and the new feature, which would involve changing line three so that it maintains its old behavior, unless the new feature is active; then it'll do the new thing. But you're afraid to do that because you don't want to break the existing feature. It's working. People are using it. Why mess with it? So instead, you copy and paste the existing code. After all, it's just four lines. And then modify the copy. Line three in the copy now does what it's supposed to for the new feature. There, now you've added the new feature. You've left the old one in place, and you can safely move on. But there's…

Contents