prompt
FreeStructured code refactoring coach using Fowler's catalog
FreeFree tier
About prompt
A specialized prompt for LLMs that transforms the AI into a senior software engineer and refactoring specialist with 15+ years of experience. It provides a structured framework to diagnose code quality issues, prioritize refactoring by impact and risk, propose concrete behavior-preserving transformations (e.g., Extract Method, Replace Conditional with Polymorphism), define a safe step-by-step sequence, and recommend validation approaches such as characterization tests. The prompt supports multiple languages including Java, Python, JavaScript, and Go, and references Martin Fowler's refactoring catalog and SOLID principles.
Key Features
Diagnoses code smells (long methods, feature envy, data clumps, primitive obsession)
Prioritizes refactoring by impact and risk (High/Medium/Low)
Proposes specific transformation patterns (Extract Method, Replace Conditional with Polymorphism, etc.)
Defines safe sequencing with rollback checkpoints per step
Recommends validation approach (characterization tests, regression checks)
Supports multiple languages (Java, Python, JavaScript, Go)
Provides before/after code examples where helpful
Emphasizes incremental, testable changes over big-bang rewrites
Pros & Cons
Pros
- Provides a structured, step-by-step refactoring plan
- All proposed transformations preserve observable behavior exactly
- Uses well-known refactoring pattern names (Fowler catalog) for developer lookup
- Includes realistic risk assessment per step
- Encourages incremental changes that keep code in a working state at each stage
Cons
- Requires manual application of each transformation step
- Limited to code refactoring; does not handle feature additions or new functionality
- Assumes intermediate team familiarity with refactoring concepts
- May not cover domain-specific or language-specific idioms without additional context
Best For
Refactoring legacy code to improve readability and maintainabilityReducing technical debt in production codebasesTraining junior developers on safe refactoring techniquesPreparing code for feature additions by reducing complexityImproving testability of tightly coupled modules
FAQ
What does the refactoring coach prompt do?
It guides an LLM to act as a senior refactoring specialist. Developers provide code and a primary goal (e.g., readability, testability), and the prompt generates a prioritized plan with specific transformation patterns and safe sequencing steps.
Which programming languages does the prompt support?
The prompt mentions Java, Python, JavaScript, and Go explicitly, and can infer other languages from the code provided.
Does the prompt suggest rewrites or incremental changes?
It strictly prioritizes incremental, testable changes over big-bang rewrites. Every proposed change must preserve observable behavior.
What refactoring patterns are referenced?
Patterns from Martin Fowler's refactoring catalog, such as Extract Method, Replace Conditional with Polymorphism, and others, are named and used in transformation steps.