← Files get-fableARCHIVED FILE
skills/fable-simplify/references/refactoring-patterns.md
1.5 KB · Oct 5, 2026 · 18:31 UTC
# Code Simplification Patterns & Altitude Improvement
## Purpose
A catalog of behavior-preserving refactoring patterns to flatten nested logic, eliminate redundant code, improve readability, and increase code altitude without changing functionality.
## Core Simplification Patterns
### 1. Guard Clauses & Early Returns
Replace deeply nested `if/else` structures with inverted early returns to keep the happy path unindented and linear.
```typescript
// Before: Deep nesting
function processOrder(order: Order) {
if (order) {
if (order.isValid) {
if (order.hasInventory) {
return execute(order);
} else {
throw new Error('Out of stock');
}
} else {
throw new Error('Invalid order');
}
}
}
// After: Clean guard clauses
function processOrder(order: Order) {
if (!order) return;
if (!order.isValid) throw new Error('Invalid order');
if (!order.hasInventory) throw new Error('Out of stock');
return execute(order);
}
```
### 2. Method Extraction for High-Level Altitude
Extract low-level details (DOM manipulation, regex parsing, byte calculations) into dedicated helper functions with descriptive names so the main orchestrator reads like a high-level narrative.
### 3. Deduplication & Shared Abstraction
Identify copy-pasted blocks across modules, extract a unified parameter-driven helper, and update all call sites.
### 4. Removal of Dead Code & Speculative Abstractions
Delete unused functions, dead branches, commented-out code, and unreferenced type definitions.
SHA-256: 6805aeb2a01cb615a222ce22c5416b2e435a5104d2cf06b5c88f0f8f06021a00