You know them, those errors that make NO sense. Where it seems like a gremlin just jumped deep inside your chips and messed up something. Do you take a walk, write stuff, call an uncle? I need help!!
|
closed as not constructive by Mark Trapp Sep 7 '11 at 18:35
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or specific expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, see the FAQ for guidance.
|
For those really horrible problems my strategy usually goes as follows.
|
||||
|
|
|
Quit. No, not your job! Just get up and go home. You're done for the day or the weekend. 19 times out of 20 when you come back to the problem next, the solution will present itself within an hour. |
|||||||||||||||||||||
|
|
Before ten hours go by, I would get some help.
|
|||||||||
|
|
One word, That and another set of eyes, is always worth more than any time you can waste staring at something. I would never spend more than 45 mins to an hour trying to solve something in one sitting, it violates the law of diminishing returns. |
||||
|
|
|
Taking a walk usually helps. Open the blinds before you go. |
|||||
|
|
Explain the problem to someone else. By explaining the problem to someone else, you have to clarify it: this often lets you see the solution. (One of the UK professional computer magazines once proposed selling life size cardboard cut-outs of a senior programmer specifically for this purpose.) I find sleeping on a problem (sometimes for a couple of days) can also help. |
|||||
|
|
I have a three step plan:
Each stage is an escalation if the previous step failed. There's almost always something else productive I can work on at stage 2. |
|||||
|
|
Sleep over it Otherwise, call someone nearby and ask him to take a quick look over the code. Often errors which would take you a long time to find (since its your code) are found very easily by others |
||||
|
|
|
You could see if getting up, pacing around, and thinking about the problem helps you find a solution. Whether or not you're actually standing or pacing, try getting away from the computer while you're thinking. |
||||
|
|
|
I generally do one of the three:
Any of the three do a good job of distracting oneself from the situation at hand. I find the distractions let my subconscious brain chew on something for a while. After an hour or so of this, bam, there's the solution :-). |
||||
|
|
|
All of these suggestions are great. However, I use a technique quite often that I didn't see mentioned. Make lists to organize your thoughts about the problem. If I have a particularly sticky problem I usually write out multiple lists such as: Facts, Assumptions, Questions, Symptoms, etc. I find that oftentimes in the process of organizing things in this way I discover assumptions I didn't realize I had (that often turn out to be wrong), questions I didn't realize need to be asked, other permutations I can check, etc. |
||||
|
|
|
Edit: The short answer: Q: How do you tackle really bizarre errors that keep you puzzled for more than 10 hours? A: Make sure they never happen: understand your design, know your code, learn how to use your debugger. Explanation: "Where it seems like a gremlin just jumped deep inside your chips and messed up something" This should never happen. If it's your code, you should have a very good idea of what is causing the error before you attempt to fix it. Futhermore, when you write your code you should already know where and why it's likely to fail. Having said that - asking a peer, posting on SO, retracing and rolling back your steps and taking a break - all the suggestions mentioned above will help. The other thing, is you must know your tools - your debugging toolkit. Logging messages at suspect points in your code, examining your call stack carefully, using conditional breakpoints and watches, etc etc. Debugging skills are not extras - they are part of programming. |
|||||||||
|
|
Build a test Harness to target that exact Defect and Isolate it Just keep eliminating good code.. while replicating the defect. Until you target the exact piece of code casing the error. Then trace the code. Recommended reading : The Pragmatic Programmer Specifically Chapter 10 : Tracer bullets |
||||
|
|
|
I had a similar problem, an apparent memory corruption in Objective-C, which I struggled with for many hours. But then me and my colleagues just took a walk for lunch, and I explained the problem (and one particular bit having to do with deserialization of an object in its init method), and basically explained the whole problem to myself. (techy details: basically, I initialized and returned an object onto something else than self, so there were two allocs, but just one object returned. Memory shifted and went crazy, crashes, and the debugger didn't really know what to do with it either). |
|||||
|
|
Take a bath. Any Rodney McKay fans? Seriously, though, if there's one commonality among all these answers, it's to take a break and do something else. I like to think of it as relegating the problem to your subconscious. Even if we are otherwise unaware, our minds (seem to) continue to work on the problem, even when we're doing something else, such as taking a bath. |
||||
|
|
|
Step through it step by step, down into assembly. Who calls what, break-point on memory access. That usually catches the bug real fast. If not, take a walk. |
||||
|
|
|
A combination of all of these :
|
||||
|
|
|
I really didn't like the most up-voted answer, because even though that sometime works, some times you just need to figure it out that same day, so what I'd recommend, in this order, is:
|
||||
|
|
|
You need to step back. My motto is 'if the problem is too hard then you are solving the wrong problem'. What are your assumptions? don't trust anything. The corollary to that is 'the weirder the problem, the weirder the solution'. The computer's strength is its logic so you can't win on logic. You have a brain and have to out-think it. In modern times there are so many other things interacting on a system - firewalls, AV, Antispyware, automatic updates happening every night - you have to deal with moving targets. |
||||
|
|
|
Google it. Stackoverflow it. Post it on forums. Basically if you can't solve it alone, get people to help. |
||||
|
|
|
||||
|
|

