Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Purpose

Duplicated Lines (%) shows a percentage of duplicated lines in the project code compared to a total amount of lines of code (LOC) on the project.

How metric helps

Some will argue that duplication is the worst coding sin because it perpetuates all the others. For instance, copying and pasting a block of code duplicates its bugs and potential bugs, its coding standards breaches, etc. Hence, increasing duplicated lines percentage can indicate such issues as bad design, lack of good inheritance structure or abstraction, copyright infringement and so on.

...

The worst consequence of a big number of duplicates is a case when a software vulnerability is copied, the vulnerability may continue to exist in the copied code if the developer is not aware of such copies. Refactoring of duplicated code can improve many software metrics, such as lines of code, complexity. This may lead to shorter compilation times, lower cognitive load, less human error, and fewer forgotten or overlooked pieces of code.

How metric works

Chart Overview

Duplicate code lines values are shown in % (Axis Y) and distributed over time (Axis YX) on the chart.

Each project child unit (can be set up in Project Configuration Wizard) in the legend is clickable, and shows/hides its percentage on the chart once clicked. The chart also adjusts a scale automatically to better fit the series shown on a screen.

2017-10-23_16-30-33.pngImage Removed

Calculation Formula

...

Calculation 

Duplicated Lines (%) is calculated as = Duplicated Lines / Total Lines * 100%.LOC * 100%,

where

Duplicated Lines - a number of duplicates

LOC - number of all code lines

RAG thresholds: Red > 20% Green <= 2%, Amber > 5%, otherwise Green<=10%, Red >10%.

Data Source

Data for the metric can be collected from Sonar or any other project tracking/engineering tool..

Insert excerpt
Integrations
Integrations
nameCopyright
nopaneltrue