Guide design decisions using the State > Coupling > Complexity > Code priority framework. Use when evaluating tradeoffs, reviewing design choices, deciding between implementations, or when code volume seems to be prioritized over deeper concerns.
Apply the code optimization priority framework: sacrifice lower priorities to improve higher ones.
State > Coupling > Complexity > Code
| Priority | Focus | Why It Matters | |----------|-------|----------------| | 1. State | Minimize mutable state | Stateless code works identically in sequential, parallel, and distributed contexts | | 2. Coupling | Reduce dependencies | Loose coupling enables independent change and testing | | 3. Complexity | Simplify logic | Lower cognitive load, fewer bugs | | 4. Code | Reduce volume | Less to read and maintain |
"It's okay to increase coupling if it makes your code more stateless."
Each level can be sacrificed to improve a higher-priority concern:
When evaluating design choices:
1. Does Option A have less mutable state than Option B?
Yes → Prefer Option A (even if more coupled/complex/verbose)
No ↓
2. Does Option A have less coupling than Option B?
Yes → Prefer Option A (even if more complex/verbose)
No ↓
3. Does Option A have less complexity than Option B?
Yes → Prefer Option A (even if more verbose)
No ↓
4. Prefer the option with less code
State is hardest to reason about:
Beginners optimize the wrong thing:
# More state, less coupling
class Processor:
def __init__(self):
self.result = None
def process(self, data):
self.result = transform(data)
def get_result(self):
return self.result
# Less state, more coupling (PREFERRED)
def process(data, transformer):
return transformer(data)
# Less code, more coupling
def create_user(data):
user = User(**data)
db.save(user) # Coupled to global db
email.send_welcome() # Coupled to global email
return user
# More code, less coupling (PREFERRED)
def create_user(data, repository, notifier):
user = User(**data)
repository.save(user)
notifier.send_welcome(user)
return user
# Less code, more complexity
result = data if condition else (default if not other else fallback)
# More code, less complexity (PREFERRED)
if condition:
result = data
elif other:
result = fallback
else:
result = default
When reviewing code or design:
| Anti-Pattern | Problem | Better Approach | |--------------|---------|-----------------| | Global singletons | Maximum coupling + hidden state | Dependency injection | | Mutable shared state | Race conditions, test complexity | Immutable data, message passing | | Clever one-liners | Complexity hidden in density | Explicit multi-line logic | | Premature DRY | Wrong abstraction, coupling | Tolerate duplication until pattern is clear |
This framework complements:
Based on: curun1r's comment on Hacker News, attributed to Sandi Metz's design principles
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer