refactoring-patterns
Skill0 starsChanged 3 months agoMITView on GitHub
重构手法:提取函数、内联、移动、简化条件、拆分循环.
9 other projects use a version of this.
Adopted by
Most recently taken up by
- proffesor-for-testing/agentic-qetheir own version, first seen Oct 25, 2026
- tmcfarlane/team-avatartheir own version, first seen Oct 20, 2026
- irahardianto/awesome-agvtheir own version, first seen Oct 14, 2026
- smileynet/code-spicetheir own version, first seen Oct 13, 2026
- Benkapner/claude-code-basecamptheir own version, first seen Sep 14, 2026
- Adhamxon/claude-code-skillstheir own version, first seen Jul 30, 2026
Other versions9 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 9
- wondelai/skills★ 2.6ksame name
- proffesor-for-testing/agentic-qe★ 524same name
- irahardianto/awesome-agv★ 157same name
- tmcfarlane/team-avatar★ 112same name
- Benkapner/claude-code-basecamp★ 17same name
- Adhamxon/claude-code-skills★ 2same name
- derheissenberg/applicaiton★ 2same name
- fabioc-aloha/alex-cognitive-architecture★ 0same name
- smileynet/code-spice★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository219 other files it gives its agents.
- agent-doctrineSkill
- agent-evaluation-frameworkSkill
- agent-visualization-flintSkill
- hermes-agentSkill
- bailian-cliSkill
- edge-browser-automationSkill
- computer-useSkill
- jupyter-live-kernelSkill
- backup-strategiesSkill
- browser-automationSkill
- chinese-ai-free-apiSkill
- cicd-pipeline-templatesSkill
- copybaraSkill
- devops-toolkitSkill
- email-deliverabilitySkill
- monitoring-observabilitySkill
- obsidian-maintenanceSkill
- obsidian-troubleshootingSkill
- openclaw-windowsSkill
- openclaw-workerSkill
- webhook-subscriptionsSkill
- windows-dev-environmentSkill
- windows-masterSkill
- zero-downtime-deploySkill
- codebase-inspectionSkill
- github-workflowSkill
- adaptive-communicationSkill
- agent-cost-dashboardSkill
- agent-evolutionSkill
- agent-governanceSkill
- agent-osSkill
- context-efficient-toolsSkill
- context-loss-awarenessSkill
- creative-synthesisSkill
- hermes-desktop-pluginsSkill
- emotional-intelligenceSkill
- graph-engineering-workflowSkill
- hermes-maintenanceSkill
- hermes-voiceSkill
- hermes-hygieneSkill
- identity-coreSkill
- income-loopSkill
- master-synthesisSkill
- meta-cognitionSkill
- reasoning-engineSkill
- self-preservationSkill
- teaching-abilitySkill
- temporal-awarenessSkill
- hermes-themesSkill
- thinking-visualizationSkill
- user-modelingSkill
- voice-full-restoreSkill
- knowledge-graph-traversalSkill
- mcp-browser-canvasSkill
- free-api-gatewaySkill
- native-mcpSkill
- web-reverse-apiSkill
- ai-edaSkill
- huggingface-hubSkill
- industrial-ai-siemens-mcpSkill
- The first 60 shown.
The file
Files
重构手法
代码坏味道(看到就要考虑重构)
1. 函数太长(> 30 行)
2. 参数太多(> 4 个)
3. 重复代码
4. 深层嵌套(> 3 层)
5. 神秘命名(看不懂的名字)
6. 全局可变状态
7. 死代码(注释掉/从未调用)
8. 大类(> 200 行)
9. 霰弹式修改(改一个功能要动很多文件)
10. 依恋情结(函数用别的类的数据多过自己的)常用重构手法
提取函数
# 重构前
def process_order(order):
# 计算总价(10行)
total = 0
for item in order.items:
if item.discount:
total += item.price * 0.8
else:
total += item.price
total += calculate_shipping(order)
# 验证库存(8行)
for item in order.items:
if item.stock < 1:
raise OutOfStock(item)
# 保存订单(5行)
db.save(order)
# 重构后
def process_order(order):
total = calculate_total(order)
validate_stock(order)
save_order(order, total)
def calculate_total(order): ...
def validate_stock(order): ...
def save_order(order, total): ...简化条件
# 重构前
if date.before(SUMMER_START) or date.after(SUMMER_END):
charge = quantity * winterRate + winterServiceCharge
else:
charge = quantity * summerRate
# 重构后
if is_summer(date):
charge = summer_charge(quantity)
else:
charge = winter_charge(quantity)卫语句(早返回)
# 重构前
def get_pay_amount():
if is_dead:
result = dead_amount()
else:
if is_separated:
result = separated_amount()
else:
if is_retired:
result = retired_amount()
else:
result = normal_amount()
return result
# 重构后
def get_pay_amount():
if is_dead: return dead_amount()
if is_separated: return separated_amount()
if is_retired: return retired_amount()
return normal_amount()以多态取代条件
# 重构前
def get_speed(bird):
if bird.type == "EUROPEAN":
return base_speed
elif bird.type == "AFRICAN":
return base_speed - load_factor * bird.coconuts
elif bird.type == "NORWEGIAN":
return 0 if bird.is_nailed else base_speed * voltage
# 重构后
class European: speed = base_speed
class African: speed = base_speed - load_factor * coconuts
class Norwegian: speed = 0 if nailed else base_speed * voltage重构安全网
1. 重构前确保有测试
2. 一次只改一处,改完跑测试
3. 小步提交(每步可回退)
4. 不要同时重构和加新功能Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

