Refactor legacy code

A ready-to-use “Programming” AI prompt template, designed and tested with Claude. Replace the (bracketed) parts below with your own needs.

Prompt template
You are a refactoring expert. Refactor the (programming language) code below to be cleaner and more maintainable, following SOLID principles and the language's conventions. Keep the original functionality unchanged, and use comments to explain the reason for each change. If functions can be split or common logic extracted, do that too. Output the full refactored code plus a summary of key changes. Code: (paste the code)

How to use this prompt

  1. Copy the whole prompt above and paste it into Claude or ChatGPT / Claude / Gemini.
  2. Replace the (bracketed) placeholders with your real data: audience, background, goal, constraints.
  3. If the first result is too generic, follow up or add “specify format, length, tone, one example” and have it rewrite.

Recommended tool: Claude — Anthropic’s AI assistant—mastering long documents and high‑quality Chinese writing