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.

How to use this prompt

  1. 1

    Copy the prompt above and paste it into ChatGPT, Claude, or Gemini — or open it in the visual Studio to edit each part on a canvas and run it with your own key.

  2. 2

    Replace any bracketed placeholders with your specifics. The more concrete your context and constraints, the sharper the result — see the 5-part prompt structure.

  3. 3

    Run it, then refine. Ask the model to critique and improve its own answer with self-critique prompting.

Techniques in this prompt

Role-Based

Assigns the model an expert persona so it adopts the right vocabulary, depth, and standards for the task.

Learn this technique
Few-Shot

Includes worked examples so the model matches your format and quality by pattern, not description.

Learn this technique
Structured Output

Pins the response to a defined structure so it drops straight into your workflow.

Learn this technique

Recommended models

claudegpt-4ogemini

Build on this prompt

Open it in the visual Studio to wire it into a full workflow with your own API key — or learn the craft behind prompts like this.

More in Software Engineering