code-refactoring-refactor-clean
You are a code refactoring expert specializing in clean code principles, SOLID design patterns, and modern software engineering best practices. Analyze and refactor the provided code to improve its quality, maintainability, and performance.
Author
Category
Development ToolsInstall
Hot:59
Download and extract to your skills directory
Copy command and send to OpenClaw for auto-install:
Download and install this skill https://openskills.cc/api/download?slug=sickn33-skills-code-refactoring-refactor-clean&locale=en&source=copy
Code Refactoring Expert - Refactor and Clean Code
Skill Overview
This is an AI skill focused on code refactoring. Based on clean code principles, SOLID design patterns, and modern software engineering best practices, it helps you analyze and refactor code to improve code quality, maintainability, and performance.
Applicable Scenarios
1. Refactoring complex, hard-to-maintain code
When code becomes messy, hard to understand, or difficult to maintain, this skill can identify code smells (such as overly long functions, duplicate code, excessive coupling) and provide an incremental refactoring plan to break complex code into clear, modular structures.
2. Reducing technical debt and code complexity
When a project has accumulated significant technical debt or the cyclomatic complexity is too high, the skill helps create a refactoring plan, apply SOLID principles and design patterns, and gradually reduce complexity so the code becomes easier to test and extend.
3. Preparing for new feature development
Before adding new features, refactor existing code to establish clear structure and boundaries, improve testability and extensibility, and ensure new features can be integrated safely and stably into the existing system.
Core Features
Code smell analysis and diagnosis
Automatically identify common problems in code, including duplicate code, overly long functions, excessive coupling, poor naming, etc., and provide concrete improvement suggestions and refactoring directions.
Incremental refactoring planning
Based on risk assessment and dependency analysis, generate an ordered plan of refactoring steps. Each step maintains functional stability, ensuring you can pause or roll back at any time, reducing refactoring risk.
Practical application of SOLID principles
Translate abstract SOLID principles into concrete refactoring actions, including single responsibility decomposition, application of the open-closed principle, Liskov substitution checks, interface segregation optimization, and implementation of dependency inversion, improving code flexibility and maintainability.
Frequently Asked Questions
What's the difference between refactoring and rewriting? Which should you choose?
Refactoring is the process of improving the internal structure of code without changing its external behavior. Rewriting is reimplementing functionality from scratch. Refactoring is suitable when the existing code logic is basically correct but the structure is poor; rewriting is suitable when the existing architecture has fundamental problems and the cost of refactoring exceeds rewriting. This skill focuses on incremental refactoring, reducing risk through small, frequent steps.
How do you ensure refactoring won't break existing functionality?
This skill adopts an incremental refactoring strategy: only a small part of the code is changed at a time, external behavior is preserved, and functionality correctness is verified through testing. Before refactoring, dependencies and risk points are assessed and reversible steps are planned. It is recommended to use automated tests; run the test suite after each refactoring step to confirm no regressions.
What kind of code should be refactored? What common signals should you watch for?
Common signals that code needs refactoring include: code smells (such as duplicate code, overly long functions, God classes), high cyclomatic complexity, difficulty in testing, changes in one place affecting many others, and code that is hard for newcomers to understand. This skill can scan code to identify these signals and provide prioritized refactoring recommendations.