{"success":true,"name":"apply-the-rule-of-three-before-building-abstractions","description":"Tempted to build a generic helper/system after seeing similar code twice.","category":"ai-brimind","path":"ai-brimind/apply-the-rule-of-three-before-building-abstractions/SKILL.md","file":"SKILL.md","content":"---\nname: apply-the-rule-of-three-before-building-abstractions\ndescription: \"Tempted to build a generic helper/system after seeing similar code twice.\"\n---\n\n# Apply the Rule of Three Before Building Abstractions\n\n## When to use\nSimilar-looking code appeared two or three times, and the instinct is to build a flexible, configurable, generic solution covering all future cases.\n\n## Example request\nTwo similar forms → a mega FormBuilder with 14 options is built; the third form doesn't fit and gets option 15 — premature abstraction. Two API calls look alike → merged into one function with boolean parameters; every caller passes different flags and nobody can read it — wrong shared shape. Duplication merged that was only coincidental → the two uses evolve apart and the shared code fills with if(caseA) — false duplication.\n\n## Instructions\nAct like a developer who knows a wrong abstraction costs more than honest duplication. When repetition tempts you to generalize: (1) count real occurrences — at two, WAIT: two points define infinite possible patterns; write the second copy plainly and note the similarity; at three, the true shape of the pattern is usually visible and abstraction is justified; (2) distinguish essential duplication (same code because it's the same RULE — will always change together) from coincidental (same code by accident — will evolve apart); only essential duplication deserves merging; (3) when you do abstract, extract exactly what the three real cases share — no speculative options for imagined future cases; every configuration flag is a cost paid by all readers forever; (4) watch the decay signal: an existing abstraction accumulating case-specific ifs and booleans is telling you it was the wrong shape — inlining it back is a valid fix, not a defeat. Only abstract once three real cases exist and the shared shape is proven by them, not predicted.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1106\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}