Are You Smart Enough To Debug Your Own Code

I collected a whole bunch of links recently and have just started going through them in depth. One of them was a blog post called A Double Handful of Programming Quotes. The first quote in the list was this one:

“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.”

- Brian Kernighan

This is one of what I like to call a thinker. What does it really mean? At first it sort of makes one think that he is saying that people are not smart enough to debug their own code. Clearly that’s not right though. Is it? I think not. What I think he is really saying is that it doesn’t pay to be too “clever” or tricky in your code. It the code you right is some sort of tour de force that takes every ounce of your skill and knowledge then you’ll be in trouble if (when) something goes wrong. This may work when you are a new programmer working hard to stretch yourself and have a mentor or instructor with far greater skill than you posses but if you know it all like some of us do … Well maybe you shouldn’t be showing off too much.

I’ve seen a lot of beginners write code that was too complex for them to debug themselves over the years. Often this happens because they try to write too much code at once before testing any of it. Or they get clever by using something they barely know and are bitten by unexpected side effects. As a teacher (or mentor) more experienced programmers see that a lot. most often it becomes a good learning experience. But for those learning on their own it can be a nightmare. That’s one of the reasons I believe most people are better off learning with others – a teacher, a senior developer or some other mentor who has gone before.

This is also an argument for keeping things as simple as possible. Sure you have to do some tuning at times. And sometimes you have to use some advanced “tricks” or tools that push you to your limit. But if/when you do you should be pretty careful how you use them. (And maybe read the documentation as well.)

Comments (6)
  1. Abdualziz says:

    Ummm, I think you are right, debugging code is too hard to beginner, but as I remember when I start my programming careers I used to document my functions and my variables, then I test each function alone after that i combining them as system requirements.

  2. Thomas, thanks for the link to your post. I should say that you have a VERY different idea of what it means to teach than I do. Very different indeed. But you are right about why I didn’t use a different title. 🙂

  3. Hi Alfred, yes that might be the reason why we disagree. I understand that now when I read your reply…

    I of course think that by working together on projects with "better developers" you’re bound to learn a lot. Though I have seen too many "schooled developers" who didn’t even know how to create "Hello World" – in *ANY* programming language – to be able to not "jump" when people mention things that appears to give the impression of that "schooling" is better then "autodidacting"… 🙂

  4. Henry Case says:

    quote is absurd…depends on the initial assertion that debugging is twice as hard as coding…not so if you write good code, then it can be easier

    too much of this kind of sophistry in programming articles from people who should very definitely know better

    note: debugging _can_ be easier than programming, you can quite easily write code that is near impossible to debug, in fact it’s the easiest thing in the world

  5. AlfredTh says:

    It is rare that debugging is easier than writing the code in the first place. Is it twice as hard? That does depend on how well the code was written in the first place. I would argue that in some cases it is much more than twice as hard to debug code when it is poorly writtend. Other times less. The whole point of the post and of the quote is the need to make sure that debugging is no harder than it really needs to be.

Comments are closed.

Skip to main content