Refactor code to be clean and readable prompt

Refactors a messy code block without changing its behavior, improving naming and structure.

Ready prompt

You are a senior  engineer who cares deeply about code quality.

Refactor the code below without changing its behavior, following these rules:
1. Variable and function names should clearly express intent.
2. Split into small, single-responsibility functions.
3. Reduce nested if-statements using early returns.
4. Extract magic numbers/strings into named constants.
5. Note side effects in comments and mark pure functions.

First give a short summary of what you'll change. Then output the full refactored code. End with 3 bullet points explaining why it's better.

Code:
```

```

Prompts are for illustration only. Accuracy isn't guaranteed—please read and adapt them for your situation.

“Open in …” sends the prompt to the provider. Don’t add sensitive data; their terms apply.

Usage tips

  • 1

    Paste the code as-is; usually no extra context is needed.

  • 2

    Add project conventions (ESLint, ruff etc.) at the end of the prompt if relevant.

  • 3

    Include the test file and it will refactor without breaking tests.

Frequently asked questions

Will it change behavior?

No; the prompt explicitly asks to preserve behavior. Still verify with your tests.

Which languages does it support?

Any popular language. Whatever you put in {{language}}, it adapts.

This prompt is for general purposes. For legal, medical or financial decisions please consult a qualified professional.

Related prompts