← Back to libraryClean up
Simplify code that grew too complex
AI-written code got long and unreadable
The prompt
This code works but is too complicated. Simplify it. ``` {{paste code}} ``` Simplification goal: {{e.g. less nesting / remove duplication / clearer names}} Behavior that must not change: {{state it explicitly}} Please: 1. In at most 3 points, where is the complexity coming from? 2. Give the full simplified code. 3. For each change, explain what you changed and why it is safer or clearer. 4. Say explicitly what you did NOT dare touch, and why. Rules: - No external behavior change; callers stay as they are. - Do not sneak in new features, abstractions or config. I asked for simplification. - If some complexity is inherent to the domain, say "this cannot be simplified further" instead of forcing it.
Replace the {{}} parts with your own content
Why it works
- "Behavior that must not change" is the safety line - without it AI quietly alters edge logic while simplifying
- Asking what it did not touch exposes the high-risk areas neither of you is sure about
- Banning new abstractions stops simplification from turning into a rewrite that is harder to read
- Letting AI say "cannot simplify this" beats forcing a simplification that introduces a bug
What it looks like
For five levels of nested conditionals, AI flattens them with guard clauses and notes which one nesting level is domain-required and must stay.
Where it bites
- Saying just "optimize this" lets AI improvise abstractions you never asked for
- Not re-testing after simplifying, so a behavior change slips through unnoticed