Live data from Hacker News

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

news.ycombinator.com

71–80 of 83 posts

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

#72

Something I read forever ago and can't find a link for: Keep a debugging journal. Take notes on every step you take and its results. It's easy to go in circles because you forget what you tried or forgot some detail of its outcome. Seeing a summary of what you already know helps you rule out possibilities and inspires new ones. I often forget to do this or feel like "I can handle this bug without a crutch". Yet every…

there has to be a way to make this more streamlined and run experiments automatically, right?

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

#73
post #4

Earlier quoted context omitted.

> What also helps is just shutting the computer off and going for a walk, generally the moment you step away you'll figure it out! Underrated. Diffused mode of brain.

Working for a bigger company I’m hesitant to go for a walk as that would mean I need to stay longer in the afternoon/evening. Even when going for a walk solves the problem, there is still little acceptance to count it as working hours. I think this mentality should shift somehow as it would benefit the company and the employee.

There's a couple of solutions to this:

1) Find an employer who doesn't pay by the hour (but e.g. per day or task/goal)

2) Find an employer who isn't strict on the hours.

3) Self employment.

4) Find or convince an employer who accepts this.

None are ideal, except for #4, but its the long breath.

And I am thoroughly convinced it works. Same with workout, mindfulness. Such behavior should be rewarded. My employer supports workout in the sense I get 1 hour per week paid leave for working out.

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

#74
Basically you have a model of your program, but the model breaks down, so you need to check that what you hold true is actually true.

Another approach is to use tools (system stats, logging, debuggers like rr/pernosco, etc).

Learn as much as you can about the system and tools you're using.

Reduce the size of the problem (reduce code, isolate, etc).

Read the code, and try to break it. Build scenarios 'this thing I see in the log can only happen if...'

Finally, there's no shame in rubber ducking a problem with a colleague!

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

#75
I guess by doing it for inappropriate amounts of time during my youth just gave me that confidence. Also I mostly debugged random problems in random stuff, so that increased my range of confidence.

Of course I've seen people who could pull out the same without having that much time. I respect and admire them.

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

#76
In the beginning of your career I think you just have to choose problems and persist on them until you've solved them no matter how long it takes (within reason). You learn from people and web research but also by doing and remembering. Persist on problems several times and you'll have started to build some intuitions on where problems hide. You'll have to persist less and less with time, but persistence almost always pays off (or you find out why a solution is impossible, which can also be interesting and useful). Eventually you become a guru. I think this is the traditional route to learning. By trying. Learning from others is another route, but trying is really the basis of learning.

Here's a trick you might find useful when you are really stuck and don't see any path forward: change some random related things in the code. If the code does not respond to those changes as you expected then that is a clue! There is something there you don't understand and the unexpected behavior is a clue to it. It's kind of like writing unit tests, checking for what you expect to be true.

Keeping a journal is essential also.

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

#77

* start logging shit, even things you know to be true / can't possibly be the problem. Somewhere your model of the code is broken, and you need to test find the breakage (model needs correction, or program needs correction). * Split the problem space. Payment messages are not getting to the slack channel. Well, is it a bug in receiving payments, or a bug sending slack messages? Check if the payments are hitting the d…

+1 to this. Make ZERO assumptions about the problem, and observe everything you reasonably can. In the increasingly (?) service-oriented architecture world, that includes fundamentals on your platform (i.e. I recall the first time I root-caused an issue that turned out to be an AWS bug) and taking the time to monitor external dependency changes (i.e. a service change, a code push, someone reverting stuff, etc.)

I also can't agree more with no shame in asking others. I would go as far as to say if you aren't asking others, you are going down a dangerous path of assuming you can solve the world's problems by yourself.

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

#78
post #38

- Create a call stack map and write it down - This will give you an overview of which classes, functions, methods, paths are being used. - People look down on console/logging, but it's useful specifically when there are race conditions or too many variables. It's way better to have several outputs and logs rather than a "standstill" picture you can only look while using the debugger. - "Learn to debug" - This advice…

> - People look down on console/logging, but it's useful specifically when there are race conditions or too many variables. It's way better to have several outputs and logs rather than a "standstill" picture you can only look while using the debugger.

It also works across every programming language and development stack. It can be setup across network and application boundaries. Debugging skills with logging is extremely portable.

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

#80

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…

This is excellent advice.
Post reply on HN