Live data from Hacker News

Why debugging is all about understanding

futurice.com

61–70 of 80 posts

Re: Why debugging is all about understanding

#61
post #58

Earlier quoted context omitted.

Wait a minute. First of all, the data is simply "there is a reproducible bug in the program". The real hypothesis is that a small, localized portion of the code is responsible for the defect. To find it, you can try binary search. If you have a better idea of the location, then by all means. Second, when you have a bug and you write a unit test, you are effectively commenting out the entire codebase except for the fu…

Part of the scientific method is that you generate hypotheses based on the data you have, not that you generate random hypotheses. It's a directed way of thinking. > The real hypothesis is that a small, localized portion of the code is responsible for the defect. To find it, you can try binary search. In your example, you used this as an assumption, not a hypothesis. And it's not quite right: the assumption you made…

Sorry, I'm kind of confused here. Why is the approach I'm defending considered random and not based on data? Is the generation of random hypotheses in general considered unscientific? What about fuzz testing or pharmaceutical R&D? What is the precise difference between hypotheses and assumptions in the context of the scientific method? What is the difference between the presence of a small portion of code being responsible and the code being more broadly responsible? Why the emphasis on presence?

Re: Why debugging is all about understanding

#62
Just add asserts to your code. Make an assert for any assumption you make no matter how trivial or unlikely to be broken. And don't disable the assert in release versions.

That can, as a very conservative estimate, cut down time spent debugging by 50%.

Life is too short to spend it debugging undefined behaviour.

Re: Why debugging is all about understanding

#64

Earlier quoted context omitted.

I agree, understanding certainly can't be emphasised enough - I believe that a good programmer must always be able to understand enough to "mentally execute" - manually stepping through code, possibly with pencil and paper or a whiteboard, and making sense of the results at each step. There are some who argue against this, and their argument is effectively "if the machine can do it for you, why should you need to kno…

But how can I mentally execute code if the whole point of the code is to interact with a third-party OS facility or application that's closed-source and therefore opaque? In that case, my mental execution of the code will depend on a mental model of the third-party component that's probably incomplete. Might as well just let the machine run the real thing.

Your mental model of the code you're reading is probably incomplete too. Just be aware of where you're less confident and then you can use different mechanisms to build that confidence when it's the most logical thing to do (running a minimal test case, or log a function return value, perhaps).

Re: Why debugging is all about understanding

#65
Using logs as a debugging tool is only step one.

The second step is using a good tool that helps you make sense of those logs, and includes good debugging information with the logs. A tool like Rollbar (disclaimer: I almost work for Rollbar) makes it super easy to analyze patterns in your errors and logging, find out who experienced the error, and to hear about the bugs before your customer, who may have become used to them.

Anecdote from my previous employer: we had a terrible piece of legacy software that regularly had modal pop-ups warning of errors this or that that doubled the amount of time our clients took to do stuff. They were so used to it that instead of reporting the error, they just dismissed them.

Re: Why debugging is all about understanding

#66
post #55
post #12

Over the years I've become more and more convinced that debugging has done a lot to develop my problem solving skills and analytical thinking in general. It's like being a full-time modern times Sherlock Holmes with the crime scene and tools neatly at your disposal. Usually breakpoints and stepping through code solves things pretty easily but some bugs can be real stumpers. Here's some of the tools I tend to use: 1.…

Regarding 7, I think you should explicitly mention "git bisect" and similar tools. (Or, are you doing that step by hand?!) For me, when I run out of ideas, "git bisect" is the most efficient debugging tool. On success, it allows me to pin down the exact commit that introduced the bug. It is very fast to do (binary search), and on success it narrows the bug down to a relatively small amount code to check. Of course, t…

I very rarely use git bisect, but the times I have were pretty fun.

And yes, it requires the type of commit history that I find not many people have the discipline to produce.

Re: Why debugging is all about understanding

#67
post #47
post #40

Also a couple of tips for the beginning programmer: * You've almost certainly not found a bug in the compiler or libraries or language runtime (somewhat more possible if you're using alpha, beta, or dev versions of something). * Your CPU, memory, or other hardware are not defective. * You are not experiencing cosmic rays flipping bits randomly in your data. * The problem is most likely to be a mistake in your code. I…

> * You've almost certainly not found a bug in the compiler or libraries or language runtime (somewhat more possible if you're using alpha, beta, or dev versions of something). This should be in bold type on every page of Stackoverflow.

But when you HAVE found a framework bug, it's both delicious and infuriating.

Re: Why debugging is all about understanding

#68

While it's great to see more attention brought to debugging, some of this is just (for lack of a better word) insane. e.g.: For searching in space, most programmers have done binary-search with commented code: comment out or bypass half of your codebase. Do that recursively until you nail down where (at which file, which function, which lines) the bug lives. No, most programmers actually haven't done this for the sim…

I listened to your DockerCon talk on debugging. So in a server that can handle multiple concurrent requests (e.g. a web application server), should each unhandled exception abort the whole process (after delivering something like an HTTP 500 to the client) so the developer can do postmortem debugging on a core dump? That would cause all other in-progress requests to be aborted too, unlike simply logging the exception…

The solution to this problem is simply process isolate, handle each request in a own process and crashing one won't affect the others. Of cause you won't get away with OS level processes.

If it interests you look at Erlang's OTP, it solved this problem years ago and works very well with that.

Re: Why debugging is all about understanding

#69
post #58

Earlier quoted context omitted.

Part of the scientific method is that you generate hypotheses based on the data you have, not that you generate random hypotheses. It's a directed way of thinking. > The real hypothesis is that a small, localized portion of the code is responsible for the defect. To find it, you can try binary search. In your example, you used this as an assumption, not a hypothesis. And it's not quite right: the assumption you made…

Sorry, I'm kind of confused here. Why is the approach I'm defending considered random and not based on data? Is the generation of random hypotheses in general considered unscientific? What about fuzz testing or pharmaceutical R&D? What is the precise difference between hypotheses and assumptions in the context of the scientific method? What is the difference between the presence of a small portion of code being respo…

Because it seems you're making an assumption about the problem being reproducible and identifiable by running half the code. I've never found this to be the case. Ever. Its a strange idea. Where does this come from? This isn't a hypothesis based on data, it is an assumption. And a bizarre one.

Re: Why debugging is all about understanding

#70
post #69

Earlier quoted context omitted.

Sorry, I'm kind of confused here. Why is the approach I'm defending considered random and not based on data? Is the generation of random hypotheses in general considered unscientific? What about fuzz testing or pharmaceutical R&D? What is the precise difference between hypotheses and assumptions in the context of the scientific method? What is the difference between the presence of a small portion of code being respo…

Because it seems you're making an assumption about the problem being reproducible and identifiable by running half the code. I've never found this to be the case. Ever. Its a strange idea. Where does this come from? This isn't a hypothesis based on data, it is an assumption. And a bizarre one.

The following program segfaults:

  main() { a(); b(); }
You don't have a debugger. You don't have the source for a or b. Strategy? Sure printf works, but so does //.
Post reply on HN