CodeAdvanced

Refactor without changing behaviour

Viktor Submitted by Viktor Added 24 days ago
Refactor the code below. The behaviour must not change, including its bugs, unless I approve the change.

Process:
1. First, describe the current behaviour precisely, including edge cases and anything that looks accidental. List the behaviours you believe are bugs and ASK before altering them.
2. Identify the seams — where this code can be split without touching callers.
3. Propose the refactor as a sequence of individually safe, individually shippable steps. For each step: what changes, what could break, and how to verify.
4. Show the code after step 1 only. I'll ask for the rest.
5. Tell me what characterisation tests to add first so the refactor is verifiable at all.
6. State what you would NOT refactor and why the churn isn't worth it.

Don't modernise style, rename things for taste, or introduce a dependency.

CODE:
{{paste}}

How to use it

Insist on step 5 before any code changes. Refactoring untested legacy code without characterisation tests is just rewriting.

Compatible popular AI tools

These tools are mapped to this prompt based on their capabilities.

People who liked this prompt

1 community likes