Skip to content
goodprompts

Refactor messy code and explain each change

The refactor gives each function one job, flattens nesting, and removes duplication, then compares line count, nesting depth, and function count.

2 blanksCodingSuggested models GPT, Claude, Geminiby @library

The prompt

849 characters
Refactor the following code to be clean, modular, and aligned with best practices. ``` ``` Apply these principles: 1. **Single Responsibility** — Each function should do one thing well 2. **Descriptive naming** — Variables and functions should reveal intent 3. **Eliminate nesting** — Break deeply nested logic into smaller functions or use early returns 4. **Remove duplication** — Extract repeated patterns into reusable utilities 5. **Simplify conditionals** — Replace complex if/else chains with clearer patterns 6. **Add type safety** — Strengthen type definitions where applicable For each change, explain: - What you changed - Why it's better - Any trade-offs introduced Show the complete refactored code, followed by a before/after comparison of key metrics (line count, nesting depth, number of functions).
849 characters

Model ratings

4.5 / 5

Strongest on the task and the fill-in blanks. Weakest on the output.

  • Astra
  • Fable
  • Neon

Worth fixing

  • It doesn't say how long or how detailed the output should be.2 of 3 models
  • It doesn't say or ask who the output is for or what it's for.1 of 3 models

Rated

Wording only. The models read the prompt without running it.

  • AstraOpenAI · gpt-6.2-astra
  • FableAnthropic · claude-fable-5-2
  • NeonGoogle · gemini-4-neon-high

About this prompt

Category
Coding
Suggested models
GPT, Claude, Gemini
Blanks
2
Published
Feb 16, 2026
Tags
#refactoring#code-review#technical

by @library

Comments

Details

Category
Coding
Suggested models
GPT, Claude, Gemini
Blanks
2
Published
Feb 16, 2026
Tags
#refactoring#code-review#technical
GoodPrompts Library@library · 94 published
View profile

Comments

No comments yet.

Remixes

No remixes yet. Create your own version of this prompt.

Remix

More like this

Frontend state audit prompt for reviewing app codeCodingPlanning and building a data animation explainer as a canvas HTML fileCodingAudit third-party API integrations for reliability and failure risksCodingReview a pull request for scope creep and risksCodingAudit a codebase for authorization and tenant isolation flawsCoding

Unfilled blanks stay as {{name}} when copied.