logoalt Hacker News

Kernighan on Programming

120 pointsby chrisjjtoday at 3:57 PM32 commentsview on HN

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

This has been a timely PSA.


Comments

awkwardtoday at 4:28 PM

Kernighan's Lever - https://linusakesson.net/programming/kernighans-lever/index....

This article is perennially posted here and is probably the best breakdown of this quote.

show 1 reply
Nevermarktoday at 8:44 PM

I consider a lot of my cleverness when writing code is aimed at achieving functionality, performance, conciseness, etc., while being easy to understand and self-debugged by design. The latter meaning:

• Types enforce safety

• Very tight dependencies

• A tight design (value, store, control flows) where most bugs are likely to be catastrophic, or at least highly visible, as apposed to silent. It works, or it doesn't.

• Use naming and code organization first, concise comments second, and a page or two of doc if all else fails, to make any non-intuitive optimization or operation intuitive again. (Clarify as needed: what it does, how it does it, and why that specific method was chosen.)

That seems so basic to writing the "most cleverest" code, that the quote makes little sense to me.

I spend a very small percentage of my time debugging, outside of the real-time development-time write, run, correct loop. If debugging ever took a significant fraction of time, it would give me some serious anxiety.

agentultratoday at 4:46 PM

So is reviewing and verifying code. Maybe not twice as "hard" if you're skilled in such things. But most programmers I've worked with can't be bothered to write tests let alone verify correctness by other means (good tests, property tests, types, model checking, etc).

It's one thing to point out small trivialities like initialization and life time issues in a small piece of code. But it's quite another to prove they don't exist in a large code base.

Kernigan is a good source of quotes and thinking on programming.

show 2 replies
shevy-javatoday at 8:10 PM

One of the few living oldschool UNIX legends still alive.

Here is when he was young:

https://www.youtube.com/watch?v=tc4ROCJYbm0

Kind of explains in an epic manner why pipes were useful back then.

They are still useful, but computers are so much more powerful that many techniques back then came primarily because their computers were not as powerful. I still, oddly enough, prefer the hardware of the 1970s, 1980s, almost early 1990s too. Today's hardware is much better, but I am nowhere as interested in it; it is now just like a common tool.

show 1 reply
jodrellblanktoday at 8:00 PM

Is there any evidence for these assertions?

Wouldn't it make intuitive sense for "writing new code to do a task" and "tracking down a problem debugging code" to be multiple different skills and not the one same skill? Wouldn't it make sense for the one you do more of to be the one you are better at, and not directly 'smart' related? Wouldn't it make sense if tooling could affect the ease of debugging?

show 2 replies
jama211today at 5:41 PM

Reading this article seems outdated and therefore quaint in some areas now, the “we’ve all felt that moment of staring at a small bit of simple code that can’t possibly be failing and yet it does” - I so rarely experience this anymore as I’d have an LLM take a look and they tend to find these sort of “stupid” bugs very quickly. But my earlier days were full of these issues so it’s almost nostalgic for me now. Bugs nowadays are far more insidious when they crop up.

show 1 reply
flippedtoday at 4:57 PM

In the age of LLMs, debugging is going to be the large part of time spent.

show 3 replies
copilot_kingtoday at 4:46 PM

[dead]

akiselevtoday at 5:08 PM

The real question is whether “debugging” the LLM is going to be as effective as debugging the code.

IME it pays dividends but it can be really painful. I’ve run into a situation multiple times where I’m using Claude Code to write something, then a week later while working it’ll come up with something like “Oh wait! Half the binaries are in .Net and not Delphi, I can just decompile them with ilspy”, effectively showing the way to a better rewrite that works better with fewer bugs that gets done in a few hours because I’ve got more experience from the v1. Either way it’s tens of thousands of lines of code that I could never have completed myself in that amount of time (which, given problems of motivation, means “at all”).

show 1 reply