Live data from Hacker News

Ask HN: How do you get better at debugging/finding a solution?

news.ycombinator.com

41–50 of 83 posts

Re: Ask HN: How do you get better at debugging/finding a solution?

#41

No joke, pen and paper, preferably a small notebook with no lines. One time I solved a very complex circular dependency issue this way. I think just writing down thoughts and process in a very human way can help with technical issues.

Agreed. When I am really stuck, I print out code that I think has a problem, bring a pencil and nothing else and go somewhere else. Coffee shop, break room, park, it doesn’t matter. Just a change of scenery. It’s amazing how well it works for focused debugging. I just need to do it more often and sooner.

Re: Ask HN: How do you get better at debugging/finding a solution?

#42
Talking to others about the problem, but more critically, take to heart and learn their debugging techniques, not just getting others to problem solve for me. I learned to use a debugger, profiler, check compiler output, rubber ducky, five whys, etc. by seeing others apply the methods. I already understood those methods existed, but they came alive and I understood them at a deeper lever by seeing others apply them.

Re: Ask HN: How do you get better at debugging/finding a solution?

#43
Use a debugger. I've gone so far as to port my linux code to windows just to use visual studio's debugger, fix the problem, then port it back.

Use version control. If the order processing worked last week and johnny made a change to order processing in this release it's highly likely it's johnny's change.

You make an assumption of where the problem is and start looking. Always understand your assumption can be wrong and you are looking in the wrong place.

Avoid code with side effects. I've taken code with bugs in it and completely rewrote all of it without side effects just to avoid those types of bugs and magically all of the hard to find bugs disappeared.

Re: Ask HN: How do you get better at debugging/finding a solution?

#44

I've mostly worked alone as a developer. No-one is going to fix it but me. Actually I think I enjoy problem solving more than the actual programming. Though frankly programming and problem solving are so closely related they are almost the same thing. I can solve most problems I come up against day to day. I guess I can't solve them all because I do ask questions on Stack Overflow sometimes. I'm not sure why, I guess…

Came here to say versions of 4 & 5. As a more junior programmer, I would sometimes resist the perceived effort or inelegance of the divide-and-conquer approach and end up spending much more time than needed to get to a solution.

Exactly, some 4 & 5 will reveal why your program isn't compiling.

Re: Ask HN: How do you get better at debugging/finding a solution?

#45
post #11

This talk, "Debugging with the Scientific Method" changed how I debug problems. I try to watch it once every year or two. tl;dr, when debugging people naturally form a hypothesis about what is going wrong and then set about gathering evidence to support or refute that hypothesis. When you do so unconciously you are very prone to biases of all sorts, most importantly confirmation bias. When you do so mindfully, and Wr…

One thing I have learned is to never say "This should work". If it doesn't work it shouldn't work.

Re: Ask HN: How do you get better at debugging/finding a solution?

#46
The problem I see a lot in people who have a hard time debugging is continuing to assume all of their base assumptions in the face of a bug. You've hit the bug because of assumptions, so ask yourself: which one of those assumptions, when changed or challenged could produce the outcome you're observing? Sometimes those assumptions are as basic as "I typed everything correctly" but other times they're more nuanced like "I assumed this library only throws when getting a transport error not an HTTP error code". IMO, it's a muscle you exercise. You build understanding in your problem space and get more skilled at identifying likely culprits for bugs. Early on though? It's a lot of asking, seeking and brute forcing.

Also, print statements or use a debugger to confirm assumptions. (I'll be honest, I rarely bring out a debugger unless a print based workflow is time consuming enough to justify remembering everything about the debugger).

Re: Ask HN: How do you get better at debugging/finding a solution?

#47
Unfortunately, there's little curation of interesting debugging case studies or "debugmes". You can try to scavenge bug trackers, but they aren't optimized for this, just a bag of itches users want to scratch. Neither are war stories very fruitful, since rarely do you get to hunt down the corresponding bugfix commits, which are essential to not miss on the details that made those bugs tricky. But then, you already have the solution in front of you.

Instead, I've found much more deliberate practice and therefore value from reverse engineering: just like in debugging, you want to understand the underlying logic through program analysis.

You can pick security CTFs, crackmes, malware samples, proprietary software with bugs you want to fix, or functionalities you want to add, or even games where you want to find some hidden content, extract some resources, or modify some behaviors. In all that you will find something of your interest, and apply approaches that I think translate well to software development:

* Differential tracing: Want to know how some action reflects in the codebase? Take k instruction traces where you do everything except that action, then take a trace where you do that action, find out what are the unique differences in that last trace. Want to know what data gets written? Same approach with memory dumps and breakpoints. How do different inputs affect these changes? You will learn to be methodic and throughout in what you test and log.

* Recognizing patterns: Sometimes you don't have symbols for your functions, are you able to identify printf at a glance, or will you waste time following the logic of the function? Do you see relative offsets being used and recognize accesses to an array? With source code all this happens on a more macro view, such as algorithms or design patterns hidden in all those coupled functions and classes. But the micro view also applies: figure out what constants relate to specific functionalities, and you can grep your way to relevant functions or documentation.

* Avoiding boilerplate: This follows from the previous point, since you want to recognize the flow of data through the codebase, in order to have some call hierarchy to follow, otherwise it's easy to waste time on functionally that is irrelevant to you. Start with how data enters the application: stdin, files, database connections, http endpoints... Tests, examples, or client apps will also help here.

Oh and don't worry about learning some assembly language, just make that investment, since that's the straightforward, well defined, predictable part.

Re: Ask HN: How do you get better at debugging/finding a solution?

#48
The biggest thing for me is just learning to accept that the problem exists and I will find the solution eventually.

Sometimes I allow myself to be annoyed that the code isn't working and that is the wrong mindset.

Everyone will experience problems but suffering is a choice.

Re: Ask HN: How do you get better at debugging/finding a solution?

#49
I think this is common enough personally.

The most important thing is understanding the problem itself. So in the case of compile issues, rust for me has just blown me away. But I won't harp on.

There are times too where it's just not clicking and you shouldn't be afraid to step away from it for a bit. I like taking a walk. But something to step away from it.

I do have crazy lows when I'm just stuck and feel so stupid at that moment. But solving it then gives that addictive high.

As for tools and those obscure errors that are impossible I'm always reminding myself of the X Y problem and to make sure I'm not getting trapped in it!

Power through though, you're not alone and all the problema you've solved you'll remember!

Re: Ask HN: How do you get better at debugging/finding a solution?

#50
Considering how you describe the problem, you just don't know the codebase?

It's hard to debug a problem if you have no idea what most of the code is supposed to do. You can go for speed - asking colleagues that do know - or you can just start following the code until you understand it. That will take more time of course, but in time you will start having enough knowledge of the code base that you can just start throwing guesses when there's a problem.

My 2 cents in case i read your question right. If i haven't, there are a few answers describing debugging techniques :)

Post reply on HN