Agent Wranglers

ARC-41Recommended

Keep each piece of knowledge in one place

Every rule, value and decision lives in one place in the code. Repeated text is fine. Repeated knowledge is not.

How to do it

When two places must change together, move the shared knowledge into one function, constant or type. For code that only looks alike, wait for the third copy before you build a shared abstraction. Two similar blocks that change for different reasons are not duplicates. A detector cannot tell the two apart, so its report is a list to read, never a gate.

Examples

JavaScript example

// Bad: the free shipping limit is written twice, and will drift
if (cart.total >= 50) shipping = 0;
banner.text = `Free shipping over €50`;

// Good: one constant holds the rule
const FREE_SHIPPING_FROM = 50;
if (cart.total >= FREE_SHIPPING_FROM) shipping = 0;
banner.text = `Free shipping over €${FREE_SHIPPING_FROM}`;

Python example

FREE_SHIPPING_FROM = 50
if cart.total >= FREE_SHIPPING_FROM:
    shipping = 0
banner_text = f"Free shipping over €{FREE_SHIPPING_FROM}"

How to check

A duplicate code detector, such as jscpd with --min-lines 10 or Pylint duplicate-code, reports repeated blocks in the build without failing it. In review, each reported block gets one answer. Would one business change need edits in both copies? If yes, the pull request merges them before it lands. Each business value, such as a price limit, appears as a literal in one file only.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/architecture/solid-and-dry/dry">Agent Wranglers clean code and architecture playbook</a>. In code you write, add a comment next to it with the same link.