一键导入
refactoring
Safely refactor code to improve structure, readability, and maintainability without changing behavior. Use proven techniques and patterns.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Safely refactor code to improve structure, readability, and maintainability without changing behavior. Use proven techniques and patterns.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | refactoring |
| description | Safely refactor code to improve structure, readability, and maintainability without changing behavior. Use proven techniques and patterns. |
| triggers | ["/refactor","/code cleanup"] |
This skill provides systematic approaches to refactoring code safely, improving structure and maintainability while preserving behavior.
Use this skill when you need to:
Golden Rule
When to Refactor
Preparation
Execution
Verification
Extract Method
# Before
def process_order(order):
print(f"Processing order {order.id}")
if order.total > 1000:
print("High value order - requires approval")
send_notification(order.manager, "Approval needed")
update_inventory(order.items)
send_confirmation(order.customer)
# After
def process_order(order):
log_order_processing(order)
if requires_approval(order):
request_approval(order)
fulfill_order(order)
def log_order_processing(order):
print(f"Processing order {order.id}")
def requires_approval(order):
return order.total > 1000
def request_approval(order):
print("High value order - requires approval")
send_notification(order.manager, "Approval needed")
def fulfill_order(order):
update_inventory(order.items)
send_confirmation(order.customer)
Introduce Parameter Object
# Before
def create_user(name, email, phone, address, city, zip_code):
pass
# After
@dataclass
class UserInfo:
name: str
email: str
phone: str
address: str
city: str
zip_code: str
def create_user(user_info: UserInfo):
pass
Replace Conditional with Polymorphism
# Before
def calculate_salary(employee):
if employee.type == "fulltime":
return employee.base_salary
elif employee.type == "contractor":
return employee.hourly_rate * employee.hours
elif employee.type == "intern":
return 0
# After
class FullTimeEmployee(Employee):
def calculate_salary(self):
return self.base_salary
class Contractor(Employee):
def calculate_salary(self):
return self.hourly_rate * self.hours
class Intern(Employee):
def calculate_salary(self):
return 0
Bloaters
Object-Orientation Abusers
Change Preventers
Dispensables
Characterization Tests When tests don't exist, write tests that capture current behavior before refactoring:
def test_current_behavior():
"""Document current behavior before refactoring."""
result = legacy_function(input_data)
assert result == expected_output # Record actual output
Parallel Implementation Keep old implementation while building new:
def process_data(data, use_new_impl=False):
if use_new_impl:
return new_implementation(data)
return old_implementation(data)
Feature Flags Enable gradual rollout of refactored code:
if feature_flags.enabled("new-payment-flow"):
process_payment_v2(order)
else:
process_payment_v1(order)
See the examples/ directory for:
extract-method-examples/ - Method extraction patternsdesign-pattern-refactorings/ - Applying design patternslegacy-code-techniques.md - Working with untested codebefore-after-comparisons.md - Real refactoring examplesInteractive onboarding workflow that interviews users to understand their coding goals and generates PR-ready implementation plans. Use when starting a new development task to ensure clear requirements and structured execution.
Implement security best practices for Gamma integration. Use when securing API keys, implementing access controls, or auditing Gamma security configuration. Trigger with phrases like "gamma security", "gamma API key security", "gamma secure", "gamma credentials", "gamma access control".
Write effective technical documentation including READMEs, API docs, architecture decisions, and inline code documentation.
Build and manage CI/CD pipelines with Azure DevOps. Configure builds, releases, and automate software delivery workflows.
Develop, deploy, and manage Azure Functions for serverless computing. Supports HTTP triggers, timers, queues, and event-driven architectures.
Manage Azure resources effectively using CLI, Portal, Bicep, and ARM templates. Use for provisioning, organizing, and maintaining cloud infrastructure.