帮助你识别职责混杂的例程,并拆分为单一职责的清晰结构。
该技能材料显示其为纯提示/文档型的开源技能,不要求密钥、无声明远程端点,也未显示本地执行或数据访问能力,整体风险较低。主要不确定性在于仓库星标低、许可证未声明且维护状态未知,但基于现有材料不足以构成高风险。
材料明确标注无需密钥或环境变量;作为纯提示型技能,未见凭证收集、存储或滥用路径。
未声明任何远程端点,且系统检查项为 prompt-only;材料中未见将用户数据发送到外部服务的描述。
该技能内容是关于代码设计原则的说明与示例,未显示会启动本地进程、执行脚本或调用系统能力。
材料未声明读写文件、访问本地资源或处理用户数据的能力;从描述看更像静态方法论提示,不涉及数据权限。
来源为 GitHub 开源仓库,源码原则上可审计,这是正面因素;但许可证未声明、社区采用度为 0 star、维护状态未知,需留意可持续性与供应链透明度。
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "Keeping Routines Focused" 技能: 1. 下载 https://raw.githubusercontent.com/obra/clank/main/skills/coding/keeping-routines-focused/SKILL.md 2. 保存为 ~/.claude/skills/keeping-routines-focused/SKILL.md 3. 装好后重载技能,告诉我可以用了
请检查下面这段代码,找出一个函数中混合了哪些不同职责,并给出按单一职责原则拆分后的重构方案与示例代码。
指出函数承担的多项任务,并提供拆分后的函数设计与重构代码示例。
请从可维护性角度评审这些例程,判断哪些例程做了不止一件事,并说明应如何提取成更专注的小例程。
给出问题例程清单、职责划分说明,以及建议的拆分方式。
基于“每个例程只做一件事”的原则,分析这段模块代码,并输出可执行的重构清单,按优先级排序。
输出按优先级排列的重构建议,帮助逐步提高代码聚焦度与可读性。
A routine should do ONE thing and do it well. This is called functional cohesion - the strongest, best kind of cohesion.
Core principle: If a routine's description contains "and", it's doing too many things. Extract into focused routines.
Goal: Improve intellectual manageability. The more focused a routine, the easier to understand, test, modify, and reuse.
Proactively (writing new code):
Reactively (improving existing code):
Warning signs routine needs focus:
One thing means one level of abstraction:
✅ Does one thing:
def calculate_total_price(items, tax_rate):
"""Calculate total price of items including tax."""
subtotal = sum(item.price * item.quantity for item in items)
tax = subtotal * tax_rate
return subtotal + tax
Single purpose: price calculation. All statements at same abstraction level (arithmetic).
❌ Does multiple things:
def handle_order(order_data, user_id):
"""
Process order:
- Validate order data
- Calculate total with tax
- Apply discount codes
- Check inventory
- Create order record
- Send confirmation email
- Update user history
- Return confirmation
"""
validated = validate_order_data(order_data, user_id) # Thing 1
subtotal = calculate_subtotal(validated["items"]) # Thing 2
discount = apply_discount(subtotal, validated.get("discount_code")) # Thing 3
tax = calculate_tax(subtotal - discount, validated["tax_rate"]) # Thing 4
total = subtotal - discount + tax # Thing 5
check_inventory(validated["items"]) # Thing 6
order_record = create_order_record(...) # Thing 7
send_confirmation_email(...) # Thing 8
update_user_history(user_id, order_record["order_id"]) # Thing 9
return {...} # Thing 10
Description has 8 "and"s. Does 10 different things. Violates single responsibility.
Group related statements, extract into focused routine:
Before (orchestrator does everything):
def handle_order(order_data, user_id):
# Validation (lines 1-10)
validated = validate_order_data(order_data, user_id)
# Pricing (lines 11-15)
subtotal = calculate_subtotal(validated["items"])
discount = apply_discount(subtotal, validated.get("discount_code"))
tax = calculate_tax(subtotal - discount, validated["tax_rate"])
total = subtotal - discount + tax
# Inventory (lines 16-20)
check_inventory(validated["items"])
# Persistence (lines 21-30)
order_record = create_order_record(...)
# Notifications (lines 31-35)
send_confirmation_email(...)
update_user_history(user_id, order_record["order_id"])
return {...}
After (each phase is focused routine):
def handle_order(order_data, user_id):
"""Single responsibility: Orchestrate order processing."""
validated_order = validate_order_request(order_data, user_id)
pricing = calculate_order_pricing(validated_order)
verify_inventory_available(validated_order)
order = create_and_save_order(validated_order, pricing, user_id)
…
先用伪代码梳理方案与迭代思路,再高效转成可执行代码。
帮助用户检索过往 Claude Code 对话,快速找回事实、决策与上下文线索。
帮助用户用接口封装实现细节,从业务层面设计与理解系统
帮助开发者保持类接口抽象一致,避免混杂序列化、持久化等无关职责。
为工程师生成分步实施计划,帮助在陌生代码库中快速落地任务。
帮助你在实施前先比较2到3种方案,选出更优设计与执行路径。
帮助开发者用单一职责变量提升代码可读性、可维护性与调试效率
帮助开发者用早返回或表驱动方式简化嵌套条件分支,提升代码可读性。
扫描多项技能并提炼通用规则,自动追加、修订或新建规则文件。
沉淀并查询代码库经验教训,帮助开发、验证与评审减少重复踩坑。
帮助你调研、规划并并行执行大规模代码变更,让多个代理分别提交 PR。
在发现关键经验后,帮助沉淀并更新可复用的技能与操作指引