KISS — Keep It Simple
Before Applying
If .agents/stack-context.md exists, read it first. Apply this principle using idiomatic patterns for the detected stack. For framework-specific details, use context7 MCP or web search — don't guess.
Principle
Given two solutions that produce the same result, prefer the one that is easier to read, understand, and change.
Why This Matters in Production
Simple code survives contact with production. Complex code breaks in ways that are hard to diagnose, hard to fix, and hard to verify the fix didn't break something else. Every incident response starts with someone reading code under pressure — if they can't understand it quickly, the outage gets longer.
Complexity compounds. A "slightly clever" solution today becomes an "incomprehensible" solution after six months of patches by three different developers.
The most dangerous bugs hide in code that's too complex for any single person to hold in their head.
Rules
- Optimize for reading, not writing. Code is read 10x more often than it's written. A few extra lines of clear code beats a one-liner that requires a comment to explain.
- Use boring technology. Prefer well-understood tools, patterns, and libraries over novel ones. Novel solutions carry hidden costs in debugging, hiring, and documentation.
- Limit nesting depth. If a function has more than 3 levels of nesting, flatten it with early returns, guard clauses, or extraction into helper functions.
- One function, one job. If you need the word "and" to describe what a function does, split it.
- Name things for what they do, not how they do it.
get_active_users() not query_db_filter_status_map_results().
- Avoid clever tricks. Bitwise hacks, regex one-liners for complex parsing, operator overloading for non-obvious operations — these optimize for the writer's ego, not the reader's comprehension.
- Prefer explicit over implicit. Magic values, hidden state, implicit type conversions, and action-at-a-distance make code unpredictable.
Anti-Patterns
- Premature optimization: Sacrificing readability for performance without profiling data showing it matters
- Abstraction astronautics: Factory factory patterns, deeply nested generics, frameworks for simple tasks
- Clever one-liners: Dense expressions that compress logic to the point of obscurity
- God functions: 200+ line functions that handle multiple concerns
- Stringly typed systems: Using raw strings where enums, types, or constants would add clarity
- Hidden control flow: Decorators, middleware chains, or event systems that make it impossible to trace what happens when a request arrives
Examples
-- Overly clever
users = {u.id: u for u in db.query(User) if u.active and u.role in roles and not u.banned}
-- Simple and scannable
active_users = db.query(User).where(active=true, banned=false)
users = filter_by_role(active_users, roles)
users_by_id = index_by(users, key="id")
-- Deeply nested
def process(data):
if data:
if data.valid:
if data.type == "order":
if data.items:
# actual logic buried 4 levels deep
-- Flattened with guard clauses
def process(data):
if not data:
return
if not data.valid:
return
if data.type != "order":
return
if not data.items:
return
# actual logic at top level
Boundaries
- Simple does not mean naive. Error handling, input validation, and proper data structures are not "complexity" — they're correctness. Don't strip away safety in the name of simplicity.
- Simple does not mean primitive. Using a well-chosen library or pattern (like a state machine for complex state transitions) can be simpler than hand-rolling the equivalent logic.
- Some domains are inherently complex. Cryptography, distributed consensus, and financial calculations have irreducible complexity. KISS means don't add unnecessary complexity on top.
- Tension with DRY: Sometimes duplicating a few lines is simpler than introducing an abstraction. Prefer the version a new team member could understand in 30 seconds.
Code Review Checklist
Related Skills
- yagni: When the complexity comes from building things you don't need yet
- separation-of-concerns: When complexity comes from mixed responsibilities
- solid: When complexity comes from poor module design
1---2name: kiss3description: When writing or reviewing code to reduce complexity and improve readability. Use when the user says "simplify this," "too complex," "hard to read," "clean up," "what does this do," or "can't follow this code." For over-engineering concerns, see yagni. For structural clarity, see separation-of-concerns.4---56# KISS — Keep It Simple78## Before Applying910If `.agents/stack-context.md` exists, read it first. Apply this principle using idiomatic patterns for the detected stack. For framework-specific details, use context7 MCP or web search — don't guess.1112## Principle1314Given two solutions that produce the same result, prefer the one that is easier to read, understand, and change.1516## Why This Matters in Production1718Simple code survives contact with production. Complex code breaks in ways that are hard to diagnose, hard to fix, and hard to verify the fix didn't break something else. Every incident response starts with someone reading code under pressure — if they can't understand it quickly, the outage gets longer.1920Complexity compounds. A "slightly clever" solution today becomes an "incomprehensible" solution after six months of patches by three different developers.2122The most dangerous bugs hide in code that's too complex for any single person to hold in their head.2324## Rules25261. **Optimize for reading, not writing.** Code is read 10x more often than it's written. A few extra lines of clear code beats a one-liner that requires a comment to explain.272. **Use boring technology.** Prefer well-understood tools, patterns, and libraries over novel ones. Novel solutions carry hidden costs in debugging, hiring, and documentation.283. **Limit nesting depth.** If a function has more than 3 levels of nesting, flatten it with early returns, guard clauses, or extraction into helper functions.294. **One function, one job.** If you need the word "and" to describe what a function does, split it.305. **Name things for what they do, not how they do it.** `get_active_users()` not `query_db_filter_status_map_results()`.316. **Avoid clever tricks.** Bitwise hacks, regex one-liners for complex parsing, operator overloading for non-obvious operations — these optimize for the writer's ego, not the reader's comprehension.327. **Prefer explicit over implicit.** Magic values, hidden state, implicit type conversions, and action-at-a-distance make code unpredictable.3334## Anti-Patterns3536- **Premature optimization:** Sacrificing readability for performance without profiling data showing it matters37- **Abstraction astronautics:** Factory factory patterns, deeply nested generics, frameworks for simple tasks38- **Clever one-liners:** Dense expressions that compress logic to the point of obscurity39- **God functions:** 200+ line functions that handle multiple concerns40- **Stringly typed systems:** Using raw strings where enums, types, or constants would add clarity41- **Hidden control flow:** Decorators, middleware chains, or event systems that make it impossible to trace what happens when a request arrives4243## Examples4445```46-- Overly clever47users = {u.id: u for u in db.query(User) if u.active and u.role in roles and not u.banned}4849-- Simple and scannable50active_users = db.query(User).where(active=true, banned=false)51users = filter_by_role(active_users, roles)52users_by_id = index_by(users, key="id")53```5455```56-- Deeply nested57def process(data):58 if data:59 if data.valid:60 if data.type == "order":61 if data.items:62 # actual logic buried 4 levels deep6364-- Flattened with guard clauses65def process(data):66 if not data:67 return68 if not data.valid:69 return70 if data.type != "order":71 return72 if not data.items:73 return74 # actual logic at top level75```7677## Boundaries7879- **Simple does not mean naive.** Error handling, input validation, and proper data structures are not "complexity" — they're correctness. Don't strip away safety in the name of simplicity.80- **Simple does not mean primitive.** Using a well-chosen library or pattern (like a state machine for complex state transitions) can be simpler than hand-rolling the equivalent logic.81- **Some domains are inherently complex.** Cryptography, distributed consensus, and financial calculations have irreducible complexity. KISS means don't add unnecessary complexity on top.82- **Tension with DRY:** Sometimes duplicating a few lines is simpler than introducing an abstraction. Prefer the version a new team member could understand in 30 seconds.8384## Code Review Checklist8586- [ ] Can a new team member understand this code without asking the author?87- [ ] Are there any "clever" shortcuts that save lines but cost clarity?88- [ ] Is nesting depth 3 or less throughout?89- [ ] Does every function have a single, clear responsibility?90- [ ] Could any complex logic be replaced with a well-named helper function?91- [ ] Are there any comments explaining "what" instead of "why"? (If so, the code itself isn't clear enough.)9293## Related Skills9495- **yagni**: When the complexity comes from building things you don't need yet96- **separation-of-concerns**: When complexity comes from mixed responsibilities97- **solid**: When complexity comes from poor module design