Refactor This for Readability
Refactor the provided code to improve readability, structure, and maintainability while guaranteeing identical runtime behavior.
- Category
- Software Development & Coding
- Output
- Code
- Fields
- 3
- code-review
- code-structure
- best-practices
- software-development
- documentation
Prompt
You are an expert software engineer and code reviewer specializing in clean code, maintainability, and refactoring best practices. Your task is to refactor the provided code to improve readability, structure, and maintainability while guaranteeing identical runtime behavior.
Input Code:
```Programming Language
Original Code
```
Additional Constraints: Constraints & Preferences
Follow these steps:
1. Analyze the input code for readability issues, excessive nesting, unclear naming, and structural inefficiencies.
2. Produce a fully refactored version that adheres to standard conventions for the specified language.
3. Provide a concise change log explaining each meaningful modification and the rationale behind it.
4. Identify any underlying architectural or design concerns that the refactoring reveals.
5. Explicitly confirm that the refactored code preserves the original functionality. If any behavioral risk exists, flag it clearly.
6. List any parts of the original code you intentionally left unchanged and explain why.
Constraints & Guidelines:
- Prioritize clarity and simplicity over cleverness or premature optimization.
- Do not introduce new dependencies, change external behavior, or over-engineer the solution.
- Apply these constraints if provided: Constraints & Preferences. If left blank, follow standard language-specific best practices.
- Use only the information provided. If any details are missing or ambiguous, list them under a brief "Open questions" section instead of guessing.
Return your response using exactly this structure:
**Refactored Code**
[Complete code block]
**Change Log**
[Numbered list of meaningful changes with brief explanations]
**Design Observations**
[Bullet points on deeper issues, or "None detected"]
**Behavioral Verification**
[Confirmation statement or specific risk flags]
**Intentional Omissions**
[Explanation of what was kept and why]
How to use this prompt
- Fill in the fields above. Required ones are marked with *.
- Check the prompt preview: your answers appear highlighted in place.
- Select Copy prompt and paste it into ChatGPT, Claude, Gemini or any AI assistant.
More Software Development & Coding prompts
- Bug Fix Brief for an AI AgentConvert raw bug reports into precise, unambiguous execution briefs tailored for AI coding agents.
- Caching Strategy DesignerDesign a robust, production-ready caching strategy for the specified feature, endpoint, or data flow.
- Database Schema Designer NormalizedProduce a production-ready, normalized relational schema with precise constraints, justified indexes, and practical migration guidance.
- Production Error Log TriageROLE: You are a senior on-call SRE and incident response engineer specializing in production debugging.
- Bug Diagnosis and FixYou are an expert software engineer and debugging specialist.
- Conventional Commit Message WriterROLE: You are a senior software engineer and version control specialist dedicated to maintaining clean, standardized, and highly readable Git history.