What problem does it solve?
This Skill eliminates the complexity and maintainability issues caused by routines that do too many things, making code harder to understand, test, and modify.
Core Features & Use Cases
- Single Responsibility Principle: Ensures each function does one thing completely and well.
- Code Extraction Techniques: Provides systematic methods to split multi-purpose routines into focused components.
- Use Case: When reviewing a 150-line function that validates user input, calculates pricing, updates inventory, and sends notifications, use this Skill to extract each responsibility into separate, testable functions.
Quick Start
Analyze this function and extract any responsibilities that violate the single responsibility principle:
def process_order(order_data, user_id):
# Validate order data
if not order_data.get("items"):
raise ValueError("No items")
# Calculate pricing
subtotal = sum(item["price"] * item["qty"] for item in order_data["items"])
tax = subtotal * 0.08
total = subtotal + tax
# Check inventory
for item in order_data["items"]:
if inventory[item["id"]] < item["qty"]:
raise InventoryError()
# Create order record
order_id = f"ORD-{datetime.now().isoformat()}"
order = {"id": order_id, "user_id": user_id, "total": total}
save_order(order)
# Send confirmation email
send_email(user_id, f"Order {order_id} confirmed")
return order