Refactor with Rationale
A refactor brief that asks for the change, the reason, and the boundary — so the resulting diff fits the seam you actually wanted to widen.
Refactor a function and explain why each change improves it. Great for code review.
Prompt
Refactor the function below for {{GOAL}} (e.g. readability, performance, testability).
<code language="{{LANGUAGE}}">
{{CODE}}
</code>
Return:
1. The refactored code in a single fenced block
2. A bulleted list of changes, each as: "Before → After: <one-line rationale>"
Do not change behavior. Preserve the function's public signature unless I say otherwise.
Variables
{{GOAL}}— what to optimize for{{LANGUAGE}}— programming language{{CODE}}— the code to refactor
When to Use
- Code review prep
- Pair programming sessions
- Learning from senior engineers
- Refactoring legacy code