Brian Kernighan’s Rule for Better Code: If It’s Too Clever, You Can’t Debug It

Brian Kernighan speaking at a microphone during Vintage Computer Festival East in 2025.


Brian Kernighan spent decades around some of the most influential software ever built. One of the rules he kept returning to was almost embarrassingly simple: if your code is too clever, you may not be clever enough to fix it later.

Brian Kernighan worked for 30 years at Bell Labs, in the computing group that helped shape Unix, and later joined Princeton’s computer science faculty. He co-authored The C Programming Language with Dennis Ritchie and wrote some of the field’s most influential books on programming style, tools and languages.

For someone with that résumé, his advice about code is surprisingly unglamorous.

“Debugging is twice as hard as writing the code in the first place.”

The rest of the idea follows naturally: if you use every bit of cleverness you have while writing a program, you leave yourself no margin for understanding it when something breaks.

This sounds like a joke about programmers. It is actually a rule about complexity.

The clever solution has a hidden price

When code works, cleverness can feel efficient. A dense expression replaces ten ordinary lines. A generic abstraction handles six cases at once. A compact trick saves a loop, an allocation or a function.

Then three months pass.

The person reading the code no longer has the entire problem in working memory. The original assumptions have faded. A production bug appears in a case nobody anticipated. The code is now being read under pressure by someone who may not have written it.

At that moment, the real cost of cleverness arrives.

The important question is no longer “How few lines did this take?” It is “How many ideas must I hold in my head at the same time to understand what this code can do?”

Kernighan’s early work on programming style pushed exactly in this direction. The goal was not to make programmers less sophisticated. It was to make programs easier for other humans to reason about.

Readable code is not beginner code

People sometimes hear “keep it simple” as “avoid advanced techniques.” That misses the point.

A sophisticated system may require sophisticated ideas. The discipline is to prevent sophistication from leaking everywhere.

If one part of a system truly needs a difficult algorithm, isolate it. Give it a name that reveals what it does. Put the assumptions next to it. Test the edges. Let the rest of the program remain boring.

Good code does not prove how much the author knows. It reduces how much the next reader must know at once.

That is why clarity scales better than cleverness. One brilliant person can understand a trick. A team, a future maintainer, an incident responder and your own tired self at 2 a.m. all need something more durable.

Most debugging starts before the bug

Kernighan and Rob Pike’s later writing on debugging makes another useful point: most bugs are ordinary, and good debugging begins by examining evidence and reasoning backward from what the program actually did.

That process gets much easier when the code has obvious boundaries.

Small functions narrow the search. Explicit state makes bad transitions visible. Clear names preserve intent. Tests turn assumptions into executable examples. Logging that records the right state can reduce hours of guessing to minutes.

None of these techniques is dramatic.

That is precisely why they work.

The AI era makes this rule more important, not less

AI can now generate working-looking code faster than most teams can review it. That changes the bottleneck.

Writing code is becoming cheaper. Understanding code is not.

A generated function may compile. It may pass the happy-path test. It may even look elegant. But the maintenance problem remains human: What assumptions did it make? What happens on failure? Is this abstraction needed? Which behavior is intentional, and which is an accident of the generated implementation?

If a tool can produce 500 lines in seconds, the temptation is to measure progress by output. But software is not valuable because many lines exist. It is valuable because the system remains understandable enough to change safely.

The faster code is produced, the more expensive unreadability becomes.

A practical rule for every pull request

Before approving code, ask four questions.

Can I explain this section without mentally executing every line? If not, the abstraction may be hiding too much or too little.

When this fails, where will I look first? If the answer is “everywhere,” the boundaries are weak.

Could the ordinary version be slightly longer but much easier to verify? Sometimes extra lines are cheaper than extra thought.

Will the next person understand why this exists? Code preserves behavior. Comments, names and structure preserve intention.

There will always be moments when a clever solution is genuinely the right solution.

But cleverness should be something a system spends deliberately, not something a programmer displays by default.

Kernighan’s warning has lasted because hardware changed, languages changed and now AI is changing how code is produced—but the person debugging at the end of the chain still has a finite brain.

How much of the code you are proudest of today will still feel obvious to someone trying to repair it a year from now?

Sources

Share this article
FacebookThreadsLinkedInX

Leave a Reply

Your email address will not be published. Required fields are marked *