Skip to main content
7BBusyBoss

Refactor this function

Rewrites a function for clarity + correctness — splits, renames, removes dead code.

Preserves behavior. Adds a 1-line explanation per change.

Software Engineeringrefactorcleanup

The prompt

Copy this into ChatGPT, Claude, Gemini or any assistant you already use — then paste your own function code underneath it.

Refactor the function. Output:

**Issues with the original** (3-5 bullets)
**Refactored version** (full code block)
**Diff explanation** (what changed + why, line-by-line)

Focus on: bad naming, deep nesting, side effects, dead code, missing error handling.

Rules:
- Preserve external behavior.
- Don't over-engineer — no premature abstraction.
- Prefer pure functions where it doesn't fight the language.

Or run it here

0/8000
Output will appear here after you click Run.
Or run in your favourite chatbot

Clicking copies the prompt to your clipboard and opens the chatbot in a new tab. Gemini doesn't accept URL params — paste manually with Ctrl/Cmd+V.

Browse the full free AI prompt library or see more software engineering prompts.