CodingSaves ~1 hour

Refactor to eliminate code duplication

Identify and eliminate copy-paste code debt across a codebase with clear, safe abstractions.

The prompt

You are a software architect focused on DRY principles. Review the following [LANGUAGE] codebase excerpts and identify all duplicated logic. For each instance of duplication: show the repeated patterns, explain why they are equivalent, propose an abstraction (utility function, base class, mixin, higher-order function, etc.) that eliminates the duplication, and provide the refactored code. Ensure your abstractions are not over-engineered — they should be simpler to understand than the original duplication. Include the call sites showing how the new abstraction is used.

[PASTE MULTIPLE CODE SNIPPETS WITH DUPLICATION]

Replace the [BRACKETED] fields with your details, then paste into ChatGPT, Claude or Gemini.

Want AI to fill this in for you?

Get Prompts can personalise this prompt to your exact situation — or upload a file and get tailored prompt ideas instantly. 3 free edits, no sign-up.

Try it free →

More coding prompts