Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

When a duplicate-code detector flags code you just wrote, inspect the structure before changing the rule. In a reported engineering anecdote, Mahiro Hirakawa’s detector caught two checks with different local names but the same underlying shape. Hirakawa chose to remove the repeated implementation, then separately checked that the refactor preserved the program’s output.

Why did the detector flag code that looked different?

Hirakawa reports that the build detector found a shared ten-line window in two checks. One used verdict_kind and verdict_unit; the other used term_kind and term_unit. The names differed, but the detector normalized the code shape by removing string literals and normalizing accessor calls. That left matching structure.

This is why a text-oriented review can miss duplication: different names and string values can make two blocks appear distinct even when they implement the same steps. As Hirakawa put it, “The duplication people actually ship is not copy-paste; it is the same structure written twice with local names.”

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The reported detection window and results are specific to Hirakawa’s project and run; they are not independently audited benchmarks.

Should you change the detector or the code?

Hirakawa considered three responses. Each changes a different thing: what the detector can catch, or whether the repeated implementation remains in the code.

Response Effect described by Hirakawa Behavior check
Add exceptions for the two files Suppresses findings in those files, including future cases there. Does not remove the repeated implementation; check behavior separately.
Increase the window from ten to eleven lines Changes the detector’s threshold and can hide future cases that fit within the new window. Does not remove the repeated implementation; check behavior separately.
Refactor the repeated code Removes the duplication instead of waiving or narrowing the detector’s finding. Requires a separate check that behavior is preserved.

In this case, the author says exceptions or a larger window would weaken future detection in their scope. The chosen response was to consolidate the repeated implementation. The finding was particularly easy to dismiss because Hirakawa had just written the code it flagged; the author treated that as a reason to inspect it, not as proof that the rule was wrong.

How was the repeated check refactored?

Hirakawa reports declaring the four repeated cells once, then reading them through a map. That keeps the shared structure in one place while allowing each check to use its own relevant values. The article reports a scaffold result of OK_SCAFFOLD faces=8/8 dup=0 and scaffold tests 67/67. These are results from that project and run, not general expectations for a deduplication change.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How can you tell whether the refactor preserved behavior?

A zero-duplication result answers only whether the detector still finds the measured duplication. It does not establish that the refactor produces the same behavior. Hirakawa therefore reports a separate comparison against the pre-refactor run: OK_ALL controls=24, with all emitted lines byte-identical to the earlier output.

That distinction is useful in any deduplication refactor: verify the code-quality goal with the detector, then verify the behavior goal with an independent control appropriate to the program. Hirakawa summarized the principle this way: “A dedup refactor needs a behaviour-preservation control, not a duplication count.” The reported control count and output comparison belong to the author’s run and have not been independently verified.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.