October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

What to Do When a Duplicate-Code Detector Flags Code You Just Wrote

Mahiro Hirakawa’s detector flagged two checks with different names but matching structure. He deduplicated the code and separately compared emitted output with the pre-refactor run.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When Mahiro Hirakawa’s build detector flagged a check he had just written, he removed the repeated implementation instead of weakening the rule. The detector had found the same code structure under different local names and string values. Hirakawa then checked the refactor separately by comparing its emitted output with the pre-refactor run.

Why did the detector flag two checks that looked different?

Hirakawa says the detector compared normalized code shapes using a ten-line window. One check used verdict_kind and verdict_unit; another used term_kind and term_unit. The local names differed, as did string values, but the detector erased string literals and normalized accessor calls. What remained was a matching structure.

As an Amazon Associate I earn from qualifying purchases.

That is why a review focused on names or a straightforward text diff can miss duplication: the surface text changes while the sequence of operations stays the same. Hirakawa’s description is an account of his project and detector, not an independently audited evaluation.

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

Should you change the detector or the code?

Hirakawa considered three responses. They differ in whether they remove the repeated implementation or suppress findings that might matter later.

Response Effect on the current finding Effect on future findings Behavior check
Except the two files Suppresses the finding in those files; the repeated implementation remains. Could hide later duplication in the same files. Does not establish whether behavior changed.
Increase the window from ten to eleven lines Changes the detector threshold rather than removing the repeated implementation. Could miss future cases that fall below the larger window. Does not establish whether behavior changed.
Deduplicate the implementation Removes the repeated structure while retaining the rule. Leaves the detector able to flag later cases under its existing setting. Requires a separate check that behavior was preserved.

He chose the third option. His reasoning was that a file exception or a larger detection window would make future findings less likely within the affected scope, while deduplication required a one-time refactor. He described the rule as a copy ban within the project tree and noted the temptation to waive a finding in code he had just written.

How did he remove the repeated code?

Hirakawa says the fix declared four repeated cells once and read them through a map. That replaced the duplicated checks with a shared implementation, rather than teaching the detector to ignore them. The article does not provide enough detail to reproduce the exact code or map structure, so the useful lesson is the refactoring shape: centralize the repeated values and have the checks read from that shared declaration.

How can you check that a deduplication preserved behavior?

A duplication count answers whether the detector still sees duplication according to its rules. It does not answer whether the refactored code emits the same results. Hirakawa treated those as separate questions: first, whether the repeated structure was gone; second, whether the output remained unchanged.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Check the structural result: Hirakawa reports OK_SCAFFOLD faces=8/8 dup=0 and scaffold tests 67/67 for his project run.
  • Check behavior independently: He reports OK_ALL controls=24 and says every emitted line was byte-identical to the pre-refactor run.

These are results reported by Hirakawa for his own project and run, not general benchmarks or independently verified results. The byte-for-byte comparison is the part that addresses behavioral preservation; dup=0 alone cannot do that.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What should you take from this case?

When a detector catches code that looks new, inspect the structure beneath the names and literals before deciding the rule is too strict. If the same implementation is genuinely repeated, deduplicate it and preserve a separate behavior check. As Hirakawa puts it, “A dedup refactor needs a behaviour-preservation control, not a duplication count.”

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.