Absolutely β you now want a **master-level prompt** that makes the AI **refactor any existing code** like the **best software engineer would**, focusing on:
- β Cleaner structure
- β Better performance
- β Reusability
- β Simplicity
- β Readability
- β Error handling
- β Modern best practices
---
## π₯ **Elite Prompt for Refactoring Code (Backend, Python, Any Language)**
> **Act as a senior software engineer and clean code expert. Your job is to refactor the following code to make it production-grade, maintainable, and elegant β without changing its core functionality.**
>
> π§ **Think deeply before you modify anything**. Analyze the code for:
>
> - Code repetition and bloating
>
> - Poor naming or structure
>
> - Missing error handling
>
> - Lack of modularity or reusability
>
> - Performance bottlenecks
>
> - Outdated or verbose syntax
>
>
> π― **Your refactored code must**:
>
> - Be cleaner, shorter, and easier to read
>
> - Follow SOLID principles (if applicable)
>
> - Use functions, classes, or modules where needed
>
> - Add appropriate error handling
>
> - Use modern best practices and libraries (e.g., `with` for file/db, `typing` hints)
>
> - Be ready for testing and scaling
>
>
> π οΈ **Instructions**:
>
> - Donβt skip reasoning: explain the improvements in a short summary before showing the final code
>
> - Then output **only** the clean, refactored code β no fluff, no repetition
>
> - Keep functions focused, name things clearly, avoid hardcoded values
>
>
> π¦ **Output format**:
>
> 1. π Summary of key improvements (2β3 bullet points)
>
> 2. 𧬠Refactored code (clean, modular, production-ready)
>
---
### π§± Optional Modular Template for Reuse
> **Act as a senior engineer. Refactor the following `[LANGUAGE]` code to improve clarity, performance, reusability, and structure. Explain why your changes improve it. Then output only the optimized version.**
---
### π§ͺ Example Use
> Refactor this Python script that inserts data into a database. Make it more modular, reusable, and readable, and add basic error handling.
---
Would you like me to show this in action by refactoring a piece of your code right now? Just paste it in.
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (0)