Code Refactoring

Developer Toolsai-coding-assistant-promptslanguagerefactoring_goaloriginal_code

Explicitly stating that external behavior must be preserved prevents breaking changes. Requiring a change log with rationale makes the refactoring reviewable and educational.

Prompt
Refactor the following {{language}} code to improve {{refactoring_goal}}.\n\nOriginal code:\n{{original_code}}\n\nConstraints:\n- Maintain the exact same external behavior (inputs and outputs must not change)\n- Do not add new dependencies unless absolutely necessary\n- Follow {{style_guide}} conventions\n\nProvide:\n1. The refactored code\n2. A bullet list of every change made and why\n3. Before/after comparison of any metrics that changed (lines of code, cyclomatic complexity, number of parameters)\n4. Any risks or trade-offs introduced by the refactoring

Variables to customize

{{language}}{{refactoring_goal}}{{original_code}}{{style_guide}}

Why this prompt works

Explicitly stating that external behavior must be preserved prevents breaking changes. Requiring a change log with rationale makes the refactoring reviewable and educational.

What you get when you save this prompt

Your workspace unlocks powerful tools to iterate and improve.

AI OPTIMIZE

AI Optimization

One-click improvement with structure analysis and pattern suggestions.

VERSION DIFF

Version History

Track every edit. Compare versions side-by-side with word-level diffs.

ORGANIZE
Development
Code Review
Testing
Marketing

Folders & Tags

Organize your library with nested folders, tags, and drag-and-drop.

MCP
$ npm i -g @promptingbox/mcp
Claude · Cursor · ChatGPT

Use Everywhere

Access prompts from Claude, Cursor, ChatGPT & more via MCP integration.

Your prompts, organized

Save, version, and access your best prompts across ChatGPT, Claude, Cursor, and more.