How do you keep AI coding tools from duplicating existing utilities?

November 27, 2026 5 answers
Asked by Trelvexo-3m

While investigating an export that skips rows without an error, I found several JSON parsing helpers. One may handle bad input differently, so merging them doesn't look entirely straightforward.

How are teams preventing this kind of duplication? Has anyone changed an AI-first policy because the code became harder to maintain?

Answers

_m53!quendavo.7

Make searching for an existing helper part of the task, not an optional extra. Give the agent a short inventory of shared utilities and where they live, then have review check whether a new helper overlaps with one already there.

That helps human contributors too. Duplicate utilities aren't unique to AI, but an agent can produce them quickly if it doesn't have enough context. Someone still needs ownership of the shared code and the decision to add to it.

q.681+zordeli:

Reusing a helper isn't always free, though. If it needs a behavior change, a separate function might be safer until the existing callers are understood.

Reply to this answer
Mavquelo-4t

I wouldn't merge those parsers based on an agent's table alone. Check their behavior on malformed input and trace the callers, especially the checkout path that might have a different error contract.

Add tests for the differences you find. Then consolidate the genuinely equivalent helpers in a small change and investigate the export bug separately. That makes it easier to tell whether a cleanup changed anything.

Trelvexo-3m:

That makes sense. The checkout behavior is the part I don't understand yet, so I'll leave it out of the consolidation for now.

Reply to this answer
Trelzari+8m

Put the explanation requirement on new shared helpers instead of hand-written code. Ask for the closest existing utility and what the new one does differently. If the difference is error handling, it belongs in a test too.

Review can catch a lot of this, and duplicate-code checks may help with obvious copies. Neither replaces someone checking whether the functions actually have the same behavior.

Reply to this answer
_h63+fendquari.5

You don't have to choose between giving an agent the whole task and banning it. Have it search, summarize call sites, or suggest a change without editing files. A developer can check the findings and decide what to implement.

For code that goes in either way, the useful rule is that a person owns and reviews it. An AI-first mandate shouldn't mean nobody can explain a module.

Reply to this answer
9k~ferrulepocket_416

Some people would rather stop using AI for coding altogether because mistakes and duplicated logic can compound. That's a reasonable preference, though workplace policies may limit that choice. At minimum, I'd push for room to write code by hand when the task calls for it, without treating that as an exception that needs defending every time.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions