kernighans-law
Skill6 starsChanged 34 days agoMITView on GitHub
Apply Kernighan's Law when reviewing code, discussing code complexity, advising on coding style, or coaching developers on how to write maintainable code. Trigger on phrases like "this clever solution", "I wrote a really elegant piece of code", "look at this one-liner", "why is this code hard to debug?", or any situation involving the trade-off between cleverness and clarity. Also trigger when someone is struggling to debug complex code or asking whether a clever approach is worth the cost.
In this repository79 other files it gives its agents.
- adr-phase-coverageSkill
- aposd-red-flag-reviewSkill
- apple-on-device-aiSkill
- artifact-gatesSkill
- asc-app-create-uiSkill
- asc-build-lifecycleSkill
- asc-cli-usageSkill
- asc-crash-triageSkill
- asc-id-resolverSkill
- asc-localize-metadataSkill
- asc-metadata-syncSkill
- asc-notarizationSkill
- asc-ppp-pricingSkill
- asc-release-flowSkill
- asc-revenuecat-catalog-syncSkill
- asc-shots-pipelineSkill
- asc-signing-setupSkill
- asc-submission-healthSkill
- asc-subscription-localizationSkill
- asc-testflight-orchestrationSkill
- asc-wall-submitSkill
- asc-workflowSkill
- asc-xcode-buildSkill
- choose-boring-technologySkill
- ci-preflightSkill
- conways-lawSkill
- cost-routingSkill
- cost-tier-routingSkill
- cunninghams-lawSkill
- ddd-strategic-auditSkill
- ddd-tactical-reviewSkill
- debug-test-captureSkill
- developing-ios-appsSkill
- doerrs-lawSkill
- fitts-lawSkill
- fix-regression-guardSkill
- galls-lawSkill
- goodharts-lawSkill
- greenspuns-tenth-ruleSkill
- gsd-core-hooksSkill
- hofstadters-lawSkill
- hyrums-lawSkill
- ios-accessibilitySkill
- ios-simulator-boot-healthSkill
- kerckhoffs-principleSkill
- knuths-optimization-principleSkill
- lady-lovelaces-objectionSkill
- leaky-abstractionsSkill
- linuss-lawSkill
- mobile-ios-designSkill
- money-boundary-judgmentSkill
- moores-lawSkill
- no-deferSkill
- norvigs-lawSkill
- parkinsons-lawSkill
- peter-principleSkill
- postels-lawSkill
- post-fix-traceSkill
- qa-test-architectSkill
- rubber-duckSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 7 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 21
Debugging difficulty: When clever code breaks, the same cleverness that makes it compact also makes the failure mode opaque.
- Distinctive: line 31
Explicit over implicit: If the reader has to mentally execute the code to understand what it does, it's too implicit.
- Distinctive: line 35
Boring over brilliant: Use standard patterns that readers recognize instantly.
- Distinctive: line 37
Comments that explain why, not what: When cleverness is unavoidable, comment the *reasoning* — not a restatement of the code.
- Distinctive: line 49
When you're debugging code you wrote: if you can barely follow your own logic, that's the bug.
- Distinctive: line 53
If you were looking at this code for the first time with no context, how long would it take to understand?
- Distinctive: line 54
When this breaks at 2am, will you be able to debug it quickly?
≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Kernighan's Law
"Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?" — Brian Kernighan, 1974 (The Elements of Programming Style)
The core idea
Writing clever code feels good. It demonstrates mastery and intelligence. But if you write code at the absolute limit of your ability to understand, you have no margin left to debug it when something goes wrong — and something will always go wrong.
The smarter move is to write code that is simpler than you're capable of. Leave yourself headroom.
What "clever" code actually costs
Time to understand: Code that is dense, abstract, or uses advanced tricks is hard to read — for you, six months later, and especially for colleagues.
Debugging difficulty: When clever code breaks, the same cleverness that makes it compact also makes the failure mode opaque. You have to fully reconstruct the intent before you can find the bug.
Review friction: Code reviewers who don't immediately understand code are slower and less thorough. Bugs slip through.
Maintenance burden: Anyone who modifies the code must first understand it. Clever code has a high "understanding tax" that gets paid over and over.
Onboarding cost: New team members struggle with overly sophisticated patterns. Institutional knowledge doesn't transfer.
What to prefer instead
Explicit over implicit. If the reader has to mentally execute the code to understand what it does, it's too implicit. Prefer code that says what it means.
Verbose over terse when it aids clarity. A 10-line version that you can read in 30 seconds is faster to work with than a 2-line version that takes 5 minutes to parse.
Boring over brilliant. Use standard patterns that readers recognize instantly. Reserve unusual approaches for cases where they provide genuine, substantial benefits.
Comments that explain why, not what. When cleverness is unavoidable, comment the reasoning — not a restatement of the code. "We use XOR swap here to avoid an allocation in the hot path" is useful. "This swaps a and b using XOR" is not.
When cleverness is worth it
Kernighan's Law is not a blanket prohibition on sophisticated code. It's a warning to be honest about the costs. Cleverness is justified when:
- It provides substantial, measurable performance gains in a proven bottleneck
- The clever pattern is well-known in your domain (bit manipulation in C, generator expressions in Python — context matters)
- It is isolated, well-commented, and unit-tested
- The team has agreed it's worth the complexity budget
The debugging corollary
When you're debugging code you wrote: if you can barely follow your own logic, that's the bug. The fix often isn't to trace the execution more carefully — it's to rewrite the code more simply, at which point the bug becomes obvious.
Key questions to surface
- If you were looking at this code for the first time with no context, how long would it take to understand?
- When this breaks at 2am, will you be able to debug it quickly?
- Can you explain this code to a teammate in under two minutes?
- Is the cleverness here buying something concrete (performance, correctness), or is it just satisfying?
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

