# Refactor code to be cleaner and easier to maintain

Improves structure, naming, and design without changing behavior.

- Topic: Software Development
- Framework: RTF
- Level: Standard
- Tags: Coding, Write, Plan, Fill-in Template
- Source: https://www.thinkwithprompt.com/prompts/refactor-code-to-be-cleaner-and-easier-to-maintain

## Prompt

```text
Refactor this code without changing its behavior.

**Language:** [LANGUAGE]
**Code:**
[PASTE]
**Goals:** [readability / testability / remove duplication / split a large function / remove dead code / apply a pattern]
**Constraints:** [public API must not change, performance limits, style guide]

Process:
1. List the code smells you see, by priority.
2. Propose a refactoring plan in small, safe steps.
3. Show the refactored code.
4. Explain each change and why behavior is preserved.
5. List tests I should run (or write) to confirm nothing broke.

If any part needs a behavior change to fix a bug, flag it separately — don't silently change it.
```

## What to fill in

- LANGUAGE
- PASTE
- public API must not change, performance limits, style guide

Free to copy and use. From ThinkWithPrompt (https://www.thinkwithprompt.com/), a library of 2,663 curated AI prompts.
