Free AI
Prompt Library
AUTOMATE / FREE PROMPT

Convert repeated code into a helper brief

Repeated code, callers and behavior that must remain unchanged.

Inputs & setup What you need before copying

Bring: REPEATED CODE

Start here: Use a working copy and preserve existing changes. If file or test access is unavailable, request a proposed patch or review rather than claimed execution.

← Automate collectionCopy · Add your context · Refine

What you need: Repeated code, callers and behavior that must remain unchanged.

Before you start: Use a working copy and preserve existing changes. If file or test access is unavailable, request a proposed patch or review rather than claimed execution.

Best for: Coding & development

Use this prompt with: A text assistant that supports your inputs.

Choose a tool that supports the files or features listed above.

Example result

Sample input

Two screens format a price with two decimals; one also adds 'USD'. Both currently accept numeric zero.

ILLUSTRATIVE SAMPLE RESULT

Shared helper can format the number to two decimals; the USD suffix stays with its caller. Characterization checks: 0 → 0.00; 2.5 → 2.50; the labeled screen → 2.50 USD. Preserve each screen's existing invalid-input behavior until a separate change is agreed.

YOUR STARTING POINT
Make it yours Fill in your details

Optional. Your details stay in this browser tab.

Read full prompt
Refactor [REPEATED CODE] only after comparing its callers. List true common behavior and intentional differences. Propose a small helper, preserve errors and return values, and add characterization checks before replacing callers. Avoid unrelated rewrites. Report actual test results or state that the proposal has not been run.

Try a variation 1 ideas

After your first result, try one of these follow-ups.

  • Adapt this result to my supplied constraints. List the missing information before making assumptions.
Check your result
  • A refactor should preserve behavior, including zero and error handling.
Where do I use this prompt?

Copy it into ChatGPT, Claude, Microsoft Copilot.

Follow the simple guide →

Weekly prompts & AI news

Useful prompts, fresh image ideas and AI updates. One email a week.

Subscribe to our weekly newsletter. Unsubscribe anytime. Privacy · Open signup form ↗

A LITTLE INSPIRATION, EVERY WEEK

Your next great AI idea
starts here.

Get useful prompts, fresh image ideas and AI news. Free, once a week.

Subscribe to our weekly newsletter. Unsubscribe anytime. Privacy · Open signup form ↗