TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

80 pointsby recvonlineover 2 years ago
Software dev with more than 10 years of experience. I always gotten praise by colleagues and companies I worked for. But, there are always moments where, without help from a colleague, I wouldn&#x27;t have found a solution to a problem.<p>When joining a new company, 2 months in, and facing a problem where code wouldn&#x27;t compile, I dig deep into the codebase but for the love of me, can&#x27;t find a solution.<p>I wonder, is that normal? Or how can I say: &quot;I don&#x27;t care, if I am alone, I can figure this out and solve it.&quot;<p>Did anyone here evolve from this state of reliance of others and turned themselves into a &quot;I can do it myself in a good amount of time&quot;?

52 comments

xsmasherover 2 years ago
* start logging shit, even things you know to be true &#x2F; can&#x27;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).<p>* 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 database. If no, you know it&#x27;s on the input side. If yes, you know it&#x27;s on the output side.<p>* Explain the problem to someone else; if you&#x27;re alone write it up like a question you&#x27;re going to post on a forum, with as much detail as possible. This must engage a different part of the brain, because often I&#x27;ll figure out the issue while writing it up I&#x27;ll reveal some clue while logging example output to add to the post.<p>Longer-term, teach a programming class! You&#x27;ll get very good at debugging issues because you&#x27;ll encounter a lot of other people&#x27;s bugs, and you&#x27;ll get a feel for what causes particular failures.<p>Also, don&#x27;t feel any shame in asking others for help. Even senior devs get blocked, and they ask other seniors, or juniors, or if juniors are not available a rubber duck will suffice.
评论 #32792781 未加载
评论 #32743359 未加载
评论 #32751256 未加载
spiffytechover 2 years ago
Something I read forever ago and can&#x27;t find a link for:<p>Keep a debugging journal. Take notes on every step you take and its results. It&#x27;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.<p>I often forget to do this or feel like &quot;I can handle this bug without a crutch&quot;. Yet every time I actually journal the process it&#x27;s helpful.
评论 #32737774 未加载
评论 #32746148 未加载
评论 #32747100 未加载
luisgvvover 2 years ago
- Create a call stack map and write it down - This will give you an overview of which classes, functions, methods, paths are being used.<p>- People look down on console&#x2F;logging, but it&#x27;s useful specifically when there are race conditions or too many variables. It&#x27;s way better to have several outputs and logs rather than a &quot;standstill&quot; picture you can only look while using the debugger.<p>- &quot;Learn to debug&quot; - This advice is thrown too vaguely around, but I&#x27;ll tell you that the 2 essential pieces that helped me debug are 1- using watches to keep an eye on variables, props that are relevant to the problem 2- Use conditional breakpoints - About the 90% of the people I&#x27;ve paired programmed with don&#x27;t know about it or even if they know it exists they don&#x27;t use it and when I put in place some conditional break points they look with awe at how it can make a change.<p>- A somewhat counter intuitive or controversial advice: read the code involved and look for inconsistencies, dumb scenarios, flags, awful named variables and clean them! - Sometimes my attention span and memory range is entangled with garbage code that makes it harder to reason about. By throwing away the pieces I don&#x27;t like and improving on them I get the benefit that in the future it will be easier to maintain and reason.
评论 #32744301 未加载
评论 #32752162 未加载
wnolensover 2 years ago
I felt like this before. Now it feels more a matter of time. I got significantly better by observing talented colleagues and picking up their strategies, some like:<p>Have a hypothesis and try to prove otherwise.<p>Start cordoning off parts of the codebase where the problem ISN&#x27;T.<p>Leave printf breadcrumbs to trace execution.<p>I find my less capable colleagues make the mistake of false assumptions, like some subroutine is executing or what state an object is in without proving it to themselves. That keeps your investigation from proceeding without luck on the larger problems.
ilitiritover 2 years ago
This is what my Mathematics Lecturer told us years ago when we had trouble understanding why some approaches worked for some problems, but not others.<p>&quot;You need a few more years of study before you can fully understand. But! You have a 600 page textbook. Do every exercise in that book. When you can do that without assistance, get another 600 page textbook and repeat.&quot;<p>He was trying to get us to build an <i>intuition</i> for certain class problem solving, while at the same time saying &quot;Shut up and calculate&quot;.<p>I find that problem-solving in the programming space is the same. Just keep doing things. You&#x27;ll develop an intuition for it eventually.
groffeeover 2 years ago
It&#x27;s probably not so much your colleague that helps but the act of just talking through a problem, inanimate objects work too <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Rubber_duck_debugging" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Rubber_duck_debugging</a><p>What also helps is just shutting the computer off and going for a walk, generally the moment you step away you&#x27;ll figure it out!
评论 #32736749 未加载
评论 #32737223 未加载
评论 #32736643 未加载
samuellover 2 years ago
I have often found myself being able to dig forward way after many of my peers (not all) are out of ideas. I have seen a shift in my own ability to debug problems after I realized that with increasing &quot;hardness&quot; of the bug, you need to just increase the level of systematicness and rigor of your method.<p>The very first thing should probably be to carefully check which commit introduced the error, and then carefully study the code changes in that one for clcues.<p>After that, and possibly based on that, what probably most people will do is start their debugging process by running a debugger through some suspicious parts of the code, based on varying degrees of well-informed suggestions.<p>For problems that escape those first tries though, what you often need to do is to start a systematic process of ruling out possible sources for the bug. In many ways this resembles scientific studies where you try to control as many variables as possible, and also include control samples with known states, trying to zoom in on only the particular variable you are studying without noise from other things.<p>That can mean feeding the system or code under study with carefully set up data for which you know what the effect should be, and then carefully trying to change each part of it and observing the outcomes. Things like that.<p>In my experience, this type of effort will eventually most often lead to the solution. The main challenge I think though, is to realize how deeply you might need to go with the systematization and automation of things, to really rule out possible sources and start zooming in on the general area around where the bug is. You might need to take some real drastic measures, and this is where I see most people who fail, don&#x27;t go far enough. Here you might need to really get away from the screen to get your thoughts flowing more freely ... but not in an undirected way, but rather trying to answer the question &quot;How can I do this in an even more systematic way ... to rule out even more possible sources, or identify unexpected behavior&quot;.<p>Not super easy to put into words, but this is in my experience the way to go.<p>Finally, one caveat is that there are certain things you should probably check before even going the systematic path. Things that can totally screw things up so that whatever you do, you never get any systematic pattern of behavior or behavior change. These things often are related to caches in various form. Make sure to turn off any and all kinds of caches in the system. They will almost guaranteed drive you insane otherwise.
评论 #32737170 未加载
Communitivityover 2 years ago
I find many problems made easier by applying cross-disciplinary knowledge.<p>Debugging has been one of those for me.<p>A long time ago I helped my mother with a murder mystery by researching how doctors diagnose things (I was a professional information broker then, with Dialog, Lexus&#x2F;Nexus, GratefulMed, etc.), as much as I could without going to medical school. I learned a lot about differential diagnosis. That got me hooked on medical shows, where I learned a little more. At some point after that I wondered if I could apply differential diagnosis methods to debugging. Because there are often multiple possible causes for a bug, I found the differential diagnosis approach to work amazingly well for me.<p>I call this process D3 (Differential Diagnosis Debugging).<p>Below is roughly how I apply it. I am working on a book including this as a couple chapters, but that won&#x27;t be out for at least another year. The material in this post is in the book, so I am told I must copyright anything smacking of an excerpt.<p>First, capture all the relevant details of the expected behavior. Create a unit test (or tests) to confirm the expected behavior.<p>Next, capture all the differences between the observed behavior and the expected behavior (the &#x27;symptoms&#x27;).<p>Then, examine those differences to come up with possible hypothesis about the causes.<p>After that, use a concept similar to Karnaugh Maps [1] to determine a sequence of small discrete unit tests whose truth (if true hypothesis could be true) determines a T or F for each hypothesis. If you wind up with more than one T then you need more tests (diagnostic testing).<p>Once you have a confirmed hypothesis, apply a fix an rerun all your tests. Rinse and repeat as needed, if needed (treatment), until all of your expected behavior tests pass.<p>Unpublished Work © Copyright 2022 William A. Barnhill, Jr. Some rights reserved. You may apply the D3 process as described herein; you may not incorporate the D3 process into a written work, a web site, or an email; you may discuss the D3 process if full attribution to the author is given.<p>Please don&#x27;t hate me for the above folks. Been told I need to include that if I want to get published.<p>[1] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Karnaugh_map" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Karnaugh_map</a>
评论 #32737222 未加载
ramesh31over 2 years ago
The most important thing I’ve learned as a dev is to be comfortable in a space I know nothing about, and to have the confidence to know “I know nothing now, but I will eventually reach the solution and fully understand it”. It’s a process. You start out groping blindly in the dark for a handhold. When you find the first one, suddenly others start falling into place. Then there’s a tiny pinhole of light that you start working towards. And all of a sudden you’re in full daylight, striding from ledge to ledge fearlessly. It’s the most beautiful thing about programming; to do this over and over again.
muzaniover 2 years ago
I use scientific method for the tougher bugs. It helps in situations where there are multiple root causes or when the testing loop is over 15 mins.<p>Write down a list of hypotheses. Then write an experiment to test it.<p>Sometimes there&#x27;s this intuition to comment out a block of code, run, and then comment out another block of code. Or revert to something before a bug happens. That&#x27;s all fine, just make sure it&#x27;s linked to a hypothesis or multiple ones.<p>Or sometimes you don&#x27;t have a hypothesis. This is where the scientific method is also useful - you know what you don&#x27;t know!<p>Then you use the Monte Carlo method, or as I call it, throwing darts and seeing if it hits a bug. Basically you slice out random blocks of possibly offending code, compile, slice out more or less, compile, until you narrow down an area.<p>From that area, you might formulate a hypothesis. Or you may need to throw more darts until you see a pattern.<p>Scientific method is bloody slow but you&#x27;ll get to the answer eventually. It&#x27;s not for everything.
评论 #32746384 未加载
rr888over 2 years ago
For a new job is a common problem. When I was younger I always thought I must be stupid because basic setup, builds are done well and I just can&#x27;t figure it out. Now I realize that most teams have random quality builds and likely there is some peculiarity that you can&#x27;t google for. You need a buddy to keep asking, also pair programming is great, if you can sit with someone else and watch what they do it really helps.
评论 #32740497 未加载
llaollehover 2 years ago
I&#x27;m fairly good at finding bugs and understanding code. Then recently I&#x27;ve had to mentor a few junior engineers and it seemed they struggled a lot.<p>It&#x27;s a mix of search space reduction + heuristics. You start looking for most probable areas of fault. This includes new commits. Then you try to partition the places where the bug could be by probablistic reasoning, logging as you go.<p>If these approaches don&#x27;t work then you start questioning your assumptions. For example, if there is eatApple() method, what did you assume about this method?<p>Did you assume all apples are rex, or is the functionality actually eatFruit()?
broastover 2 years ago
The code your dealing with is probably deterministic. The answer is in the code. Read the code. Run a mental model. Use your creativity, imagine edge cases to the code you see, and investigate what would happen and if that is what is happening. Rinse, repeat.
spuzover 2 years ago
If you often find yourself requesting help, ask yourself &quot;what would X do in this situation&quot;? I often find I can anticipate the questions a colleague would ask me when I present them a problem I&#x27;m facing. Sometimes simply trying to answer those questions will reveal the solution. Good questions for any problem are:<p>* When did this start happening?<p>* What changed between when it was working when it stopped working?<p>* Have you asked person Y who worked on that change?
评论 #32737901 未加载
aradox66over 2 years ago
Learn to use a debugger.<p>This advice would be very obvious to many, but I&#x27;m constantly surprised by how many of my coworkers don&#x27;t know how to do this and test code by pushing logging statements into a production environment.
评论 #32743291 未加载
seancover 2 years ago
This talk, &quot;Debugging with the Scientific Method&quot; changed how I debug problems. I try to watch it once every year or two.<p>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.<p>When you do so mindfully, and Write It All Down then you are much more likely to a) come up with an evidence gathering exercise which will usefully falsify your hypothesis, and b) respect the gathered evidence, reject the now false hypothesis, and move on to a new one.<p><a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=FihU5JxmnBg" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=FihU5JxmnBg</a>
评论 #32738371 未加载
评论 #32738740 未加载
tpoacherover 2 years ago
I often tend to sprinkle conditional code with &quot;in theory you shouldn&#x27;t ever get here&quot; printouts.<p>They get triggered more often than you&#x27;d think.
评论 #32744730 未加载
bilekasover 2 years ago
I think this is common enough personally.<p>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&#x27;t harp on.<p>There are times too where it&#x27;s just not clicking and you shouldn&#x27;t be afraid to step away from it for a bit. I like taking a walk. But something to step away from it.<p>I do have crazy lows when I&#x27;m just stuck and feel so stupid at that moment. But solving it then gives that addictive high.<p>As for tools and those obscure errors that are impossible I&#x27;m always reminding myself of the X Y problem and to make sure I&#x27;m not getting trapped in it!<p>Power through though, you&#x27;re not alone and all the problema you&#x27;ve solved you&#x27;ll remember!
drooblesover 2 years ago
No joke, pen and paper, preferably a small notebook with no lines.<p>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.
评论 #32738415 未加载
ltbarcly3over 2 years ago
I&#x27;ve been described as being quite good at debugging, here is my approach:<p>Short term - while debugging a problem: 1. Gather whatever information you can. Look in the logs! 2. Debugging means tracking the flow of execution from beginning to end (and then back to the front in many cases). Where along that chain is the breakdown? 3. Often you can stop after 2, since when the point of failure is determined the issue becomes obvious. However, in some cases it is not obvious. In those cases, you have to look for &#x27;something that does not make sense&#x27; or can&#x27;t be true.<p>Case study: timeouts We started having errors on a service we owned. Calls would be made to our service (call it service A) and then calls to an upstream service (service B) would time out, and we didn&#x27;t catch this exception so the request to A would end with a 500 response. However, when we looked at the logs for B we could see our requests from A and that they were not timing out at all, they were taking the usual amount of time. This is a huge contradiction! After a day of poking around we could reproduce the timeout with a script which called our service. Thinking it might be the load balancer, we started sending requests to the IP&#x27;s of workers directly, which never timed out. On a hunch, we sent requests to the IP of the load balancer (this can&#x27;t be done directly since the LB uses the hostname as part of how it routes requests to servers, but we could do this by adding the LB with the proper hostname to the &#x2F;etc&#x2F;hosts file.) Low and behold, the timeouts were still gone even though we were doing &#x27;the exact same thing&#x27; as before! Removing the entry from the hosts file, the timeouts immediately came back for the same small percentage of requests.<p>Long term: Being good at debugging really consists of two things, knowing how things work and spending the time required to debug things. Interestingly, one great way to learn how things work is to debug things. Whenever something does not make sense, or you can&#x27;t explain it, dig in and get to the bottom of it. Every time you do this you&#x27;ll learn things that you never would have guessed, and your ability to debug some random future issue will go way up when that future issue just happens to intersect something that you had to dig into previously.
Thursday24over 2 years ago
I for one consider social methods part of the problem solving process.<p>Knowing who knows what, and who can help, and asking for help the right way is key to getting better at problem solving.<p>Perhaps it is the school system that discourages problem solving through social means, and people feel guilty about taking help.<p>However, consider this perspective. What if the ones who could put together people into functional groups could be considered great problem solvers? Consider any of the great American enterprises, there are people at the top who figured out how to put people together to get things done.
Agingcoderover 2 years ago
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.<p>Another approach is to use tools (system stats, logging, debuggers like rr&#x2F;pernosco, etc).<p>Learn as much as you can about the system and tools you&#x27;re using.<p>Reduce the size of the problem (reduce code, isolate, etc).<p>Read the code, and try to break it. Build scenarios &#x27;this thing I see in the log can only happen if...&#x27;<p>Finally, there&#x27;s no shame in rubber ducking a problem with a colleague!
rapjr9over 2 years ago
In the beginning of your career I think you just have to choose problems and persist on them until you&#x27;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&#x27;ll have started to build some intuitions on where problems hide. You&#x27;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.<p>Here&#x27;s a trick you might find useful when you are really stuck and don&#x27;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&#x27;t understand and the unexpected behavior is a clue to it. It&#x27;s kind of like writing unit tests, checking for what you expect to be true.<p>Keeping a journal is essential also.
dncornholioover 2 years ago
If you relied on others, did you take something out of it other than their answer? Did you pick up how they attacked the problem in a different way? That&#x27;s how you evolve. Just observe :) Ask them how they found a way, when you couldn&#x27;t.<p>If the problem is too obscure, I &#x27;just&#x27; rebuild the system like I imagined it.<p>But I don&#x27;t think everyone is as suited to this form of tackling problems. You might get more enjoyment out of creating new things?
xyzzy4747over 2 years ago
If you can’t figure out a problem, just go back to the basics.<p>Comment out or delete the code until the fundamentals of the system works. Then add stuff back until errors happen. Also add better logging to track down the problem. Tear down the system and build it back up. Delete nonstandard approaches you can’t figure out and use standard ones from QuickStart tutorials. It might be slow progress but progress will be made.
davidjfelixover 2 years ago
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&#x27;ve hit the bug because of assumptions, so ask yourself: which one of those assumptions, when changed or challenged could produce the outcome you&#x27;re observing? Sometimes those assumptions are as basic as &quot;I typed everything correctly&quot; but other times they&#x27;re more nuanced like &quot;I assumed this library only throws when getting a transport error not an HTTP error code&quot;. IMO, it&#x27;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&#x27;s a lot of asking, seeking and brute forcing.<p>Also, print statements or use a debugger to confirm assumptions. (I&#x27;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).
gigatexalover 2 years ago
I am struggling with this now, too. We&#x27;ve built a data solution on top of some highly custom dynamic dag building stuff off of airflow but the local run-me story is very tough and I&#x27;ve yet to get a debug session working which would be nice to be able to attach to a running container of it all. Not adding much I guess just saying +1.
评论 #32738051 未加载
BlameKanedaover 2 years ago
At my previous job I was debugging a problem that a client ran into. Looking back, these are some of the steps I took:<p>1. <i>Recreate problem in prod</i> - How was it triggered? I did a bit of digging and noticed that it happened when very specific conditions occurred.<p>2. <i>Recreate it locally</i> - Got an error message, i.e. `SomeVar is not defined`.<p>3. <i>SomeVar</i> - <i>Why</i> is it `undefined`? I started working backwards and realized that the `SomeVar` functionality was working as intended, but it&#x27;s what was being fed <i>into</i> it that was the issue.<p>4. <i>Working backwards</i> - I had a hunch as to why the error was occurring when I started, and when I worked backwards I realized that I was partially correct.<p>5. <i>More research</i> - In regards to point 4, I learned what else was missing (i.e. why I was partially correct about my hunch).<p>6. <i>Start coding</i> - Since the issue was in prod, I put in a pretty shoddy hotfix. It worked, but it tacked on some logic into code that was already pretty confusing (due to a lot of conditional scenarios in the UI).<p>7. <i>PR</i> - I opened a PR, but to my Sr Dev&#x27;s point the solution worked but the code wasn&#x27;t clean.<p>8. <i>Sr Dev chat</i> - We had a quick chat, and even though the issue was in prod only a <i>few</i> people had it happening to them (the feature wasn&#x27;t widely used). Also, unless we were actively losing money due to a prod issue, a hotfix isn&#x27;t needed and we can take the time to write cleanly.<p>9. <i>Coding</i> - I realized that there was an even <i>easier</i> way to write the code without introducing confusing logic. I scrapped about 95% of what I had and put in something that not only worked, but was much cleaner. I also wrote some tests, as per the Sr&#x27;s recommendation.<p>10. <i>Updated PR</i> - I followed-up with the Sr, who thanked me for revising the code and for writing the tests.<p>---<p>Although I reached the original solution and the new one on my own, having discussions with the Senior Dev was incredibly beneficial.
andrewstuartover 2 years ago
I&#x27;ve mostly worked alone as a developer. No-one is going to fix it but me.<p>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.<p>I can solve most problems I come up against day to day. I guess I can&#x27;t solve them all because I do ask questions on Stack Overflow sometimes.<p>I&#x27;m not sure why, I guess it&#x27;s a few things:<p>1: As I said, I enjoy problem solving - it feels like a game<p>2: I have more than 35 years hard computer problem solving, so there&#x27;s alot of experience which helps.<p>3: I understand, and make a deliberate effort to understand, as much as I possibly can about every aspect of computer systems from hardware to operating system to database, to cloud to front end to back end.<p>4: I use the tried and tested problem solving method of divide and conquer - when you have a problem, break the software in half and keep doing so until you find where the problem is.<p>5: If you are still stuck, try to create a minimal test case the demonstrates the problem - this often solves it, and if it doesn&#x27;t then you can post the minimal test case on StackOverflow.<p>6: Only ever work on one thing at a time.<p>7: Work hard to learn how to use problem solving tools.... the debugger in the browser, make sure you know a little strace for doing things like tracking what file the operating system is trying to open, ngrep so you can watch data passing over the network.<p>8: Be relentless. Sometimes I think this is a personality &quot;issue&quot;, but I literally will work for 10 hours at a time trying to solve a problem until I crack it. I really don&#x27;t like finishing work without having all the days problems solved. I just grind and grind and grind on problems until I work it out.<p>9: Have a really thorough knowledge of the technologies you are working with - don&#x27;t be satisfied with learning as you go - actually take the time to read the language specification for the languages you program with, stuff like that.<p>10: Use a really good IDE and make sure you know how to use its ability to jump through the code, to jump to function definitions. You need to be good at following the logic of the program.<p>11: And finally, if no matter what you do the error remains the same, then you are probably not even working on the correct code.<p>In the case for example of why a program won&#x27;t compile, well just start cutting code out until something compiles, then add it back in little by little until you work out where the line is that fails. Even better is to use appropriate debugging tools, but divide and conquer always works.<p>There&#x27;s also no shame in scattering these everywhere you suspect the problem might be:<p>print(&#x27;got here!&#x27;)
评论 #32737945 未加载
评论 #32764120 未加载
oshirisukiover 2 years ago
I think sometimes not being able to get a software system with hundreds of thousands, or even millions of lines of code to compile is fine?<p>unless you didn&#x27;t even do any changes, and it&#x27;s a matter of the codebase requiring a specific environment or option to compile and you not having&#x2F;knowing it<p>on getting better at debugging, I would try to isolate possible sources of the problem, form a hypothesis, test it experimentally<p>you&#x27;ll need to know what you know<p>is it the environment you have? networking? OS? etc., whatever applies to your system<p>I think having a known working state is probably the most useful, though it might be difficult to get<p>something to consider, I do remember there being a paper on getting wrong results even when doing nothing wrong
Tainnorover 2 years ago
I don&#x27;t know if I&#x27;m &quot;good&quot;, i.e. efficient at debugging. I&#x27;m just incredibly persistent. If that means stepping through 20 layers of framework code... so be it. I&#x27;ve found weird undocumented edge cases that way.<p>That said, you mention not getting your code to compile. I&#x27;ve never (at least not in recent memory) not been able to get my code to compile by myself after a while, but I also don&#x27;t know what language you&#x27;re working with. Are you struggling with the type system? That can usually be tackled by taking expressions apart, assigning them explicit types and then reasoning through the inputs and outputs (with pen and paper if need be).
snarfyover 2 years ago
Use a debugger. I&#x27;ve gone so far as to port my linux code to windows just to use visual studio&#x27;s debugger, fix the problem, then port it back.<p>Use version control. If the order processing worked last week and johnny made a change to order processing in this release it&#x27;s highly likely it&#x27;s johnny&#x27;s change.<p>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.<p>Avoid code with side effects. I&#x27;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.
enoentover 2 years ago
Unfortunately, there&#x27;s little curation of interesting debugging case studies or &quot;debugmes&quot;. You can try to scavenge bug trackers, but they aren&#x27;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.<p>Instead, I&#x27;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.<p>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:<p>* 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.<p>* Recognizing patterns: Sometimes you don&#x27;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.<p>* 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&#x27;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.<p>Oh and don&#x27;t worry about learning some assembly language, just make that investment, since that&#x27;s the straightforward, well defined, predictable part.
nottorpover 2 years ago
Considering how you describe the problem, you just don&#x27;t know the codebase?<p>It&#x27;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&#x27;s a problem.<p>My 2 cents in case i read your question right. If i haven&#x27;t, there are a few answers describing debugging techniques :)
ericmcerover 2 years ago
Ask someone? If you have ever been part of a founding dev team you know there is gonna be stuff in the code that is unpleasant to untangle unless you are acquainted with how&#x2F;why it was done. If you have some kinda searchable chat&#x2F;FAQ thing I am sure someone has encountered this before or will in the future. I always thought slack was pretty good at storing years of dev questions threads in a single channel due to its informal question&#x2F;answer nature vs something like stack overflow or Confluence
mav88over 2 years ago
To improve your debugging, improve your mental model of the system you&#x27;re tackling. The more you know about the state and flow of data at every point, the more you can reason about what&#x27;s going on. I&#x27;m a particularly average programmer who is actually quite slow at banging out new code but I have fixed very difficult bugs in cloud deployments, libraries, firmware and realtime industrial systems just by laser focusing on what the system should be doing.
ebrewsteover 2 years ago
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.
ravishiover 2 years ago
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.<p>Of course I&#x27;ve seen people who could pull out the same without having that much time. I respect and admire them.
bil7over 2 years ago
the truth is you probably overcome many blockers a day that would stump others. It&#x27;s ok to rely on others&#x2F;the internet. I&#x27;m never ever mad when someone asks me for help, unless it&#x27;s the same question they&#x27;ve asked 5 times already.
MrFantasticover 2 years ago
The biggest thing for me is just learning to accept that the problem exists and I will find the solution eventually.<p>Sometimes I allow myself to be annoyed that the code isn&#x27;t working and that is the wrong mindset.<p>Everyone will experience problems but suffering is a choice.
pauleibyeover 2 years ago
Spend time installing a good low friction debugger and get good at using it! Screw log lines for local debugging, debugging is a skill in itself that needs to be practiced.
hemapaniover 2 years ago
this book is a very good discussion about debugging, &quot;Debugging: The 9 Indispensable Rules for Finding Even the Most Elusive Software and Hardware Problems&quot;, <a href="https:&#x2F;&#x2F;embeddedartistry.com&#x2F;blog&#x2F;2017&#x2F;09&#x2F;06&#x2F;debugging-9-indispensable-rules&#x2F;" rel="nofollow">https:&#x2F;&#x2F;embeddedartistry.com&#x2F;blog&#x2F;2017&#x2F;09&#x2F;06&#x2F;debugging-9-ind...</a>
hakreover 2 years ago
You can&#x27;t find a solution? There is no revision of the source code that still compiles? Then find that revision first.<p>Divide and conquer.<p>And define things out of existence.
shaolinspiritover 2 years ago
rest more, sleep on the problem. usually I get the eurika moment when I&#x27;m away from the hard problem, not when I&#x27;m on it
aparticleofuover 2 years ago
Bugs are like particles in this universe, If you feel like it nothing you will find it.
eofover 2 years ago
tl;dr rely even more on others in the most transparent way to constantly get unblocked as quickly as possible. Don’t let your ego stop you from learning something.<p>I’m grunching this thread. But I have 20ish years of experience and consider myself a decent debugger and considered enough so by others that I’ve been asked this line of questioning while in a mentorship role on a number of occasions.<p>The number one thing is simply humility; asking the dumb question in the smartest way you can, as quickly as possible, to the person who can most likely give you the best answer.<p>As you’re learning and starting out, you may not have great resources for such, but within most orgs you should be able to find where the answers are, and first ask the dumb questions (caveated by what you do understand), then eventually ask for a brain dump.<p>It is through the accumulation of tons of disparate idiosyncratic knowledge that little clues and common patterns emerge that allow people to sniff out a root cause hypothesis before the facts are even in, and often be right.<p>But people who hide their ignorance, refuse to ask questions that may make them look silly, refuse to be the idiot in the room, they learn much less quickly because they don’t get unblocked as quickly.
joshxyzover 2 years ago
Simply get good at gaslighting yourself to keep yourself going on until you solve it.
wahnfriedenover 2 years ago
start with investing in devops for extremely tight feedback loops and exploratory instrumentation<p>get good at finding and reaching out to contractable experts for rabbit-holes, whether for the spot-work or to pair on solving with their expertise
shahbabyover 2 years ago
&quot;A problem well-stated is half-solved.&quot;
codenbrewwover 2 years ago
Tests
sejjeover 2 years ago
Take a walk.<p>Rubber duck it.<p>Never quit.
barrenkoover 2 years ago
I guess the TL;DR is &quot;Keep failing&quot;, but I struggle from heavy imposter syndrome myself. Well, definitely an imposter at the moment.