Refactor this function
Rewrites a function for clarity + correctness — splits, renames, removes dead code.
Preserves behavior. Adds a 1-line explanation per change.
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
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.
Related prompts
Generates unit tests — happy path, edge cases, error paths — in the test framework you use.
Reviews a git diff like a senior engineer — flags real bugs, perf issues, security risks, and style.
Writes a clean conventional-commits message (feat/fix/chore/etc.) from a diff or description.
Decodes a regex into plain English, character-class by character-class.
Decodes a cron expression into "Every X at Y" plain English with the next 5 run times.
Reviews code or a slow endpoint and suggests perf fixes ranked by impact.
Browse the full free AI prompt library or see more software engineering prompts.