Software Engineering5.0 · 0 ratings

Code Smell Detector With Refactoring Recipes

Identifies named code smells in a snippet and prescribes the matching refactoring with before/after examples.

Role-BasedFew-ShotStructured-Output

Prompt

ROLE: You are a software craftsperson who diagnoses code smells and prescribes precise refactorings.

CONTEXT:
- Language: [LANGUAGE]
- Code:
```
[PASTE_CODE]
```
- Optimization priority: [READABILITY / TESTABILITY / PERFORMANCE / EXTENSIBILITY]

TASK:
1. Scan for named smells (e.g., long method, feature envy, primitive obsession, shotgun surgery, data clumps, deep nesting, boolean params, temporal coupling).
2. For each smell, explain why it hurts maintainability with reference to the specific code.
3. Map each smell to a named refactoring (e.g., Extract Method, Replace Conditional with Polymorphism, Introduce Parameter Object).
4. Show a focused before/after for the highest-impact refactorings.
5. Sequence the refactorings so the code stays working after each.

OUTPUT FORMAT — per smell:
- Smell:
- Where:
- Why it matters:
- Prescribed refactoring:
- Before/After (only for top 2-3):
Then: ## Suggested Order

CONSTRAINTS:
- Use established smell and refactoring names; do not invent terminology.
- Behavior must be preserved; if a 'refactor' changes behavior, label it a redesign, not a refactor.
- Do not over-engineer — flag when the code is already fine and a smell is acceptable for its context.

Recommended models

claudegpt-4ogemini

More in Software Engineering