News for hackers. Stuff that matters.
Re:Why debugging is all about understanding by userbinator on Thursday August 06, 2015 @08:55AM (#10016042)
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 know how to do it mentally" --- it fails miserably when debugging, precisely the time when the machine can't do it.

I've heard it phrased thus: "If you don't understand precisely what you need to do, what makes you think you can tell a computer how to do it?"

Re:Why debugging is all about understanding by JustSomeNobody on Thursday August 06, 2015 @09:07AM (#10016096)
I think a pencil and paper are a programmers best friend. I find it helps me work through complex logic easier when I'm debugging. I find it helps me write cleaner code when I'm tasked with something challenging. I keep a notebook next to me when coding or debugging. I try to write down my thought process when writing new code. When debugging, I write the recreate steps (if there aren't any already), and any insteresting notes about the bug while I'm tracking it down. I write down anything I think the 'fix' may impact (I also email the team about those). Basically anything and everything.
Re:Why debugging is all about understanding by taeric on Thursday August 06, 2015 @11:12AM (#10016983)
I have a similar quip that not many in my office find popular. Basically, if you can't manually test something, what makes you think you can automated the test?
Re:Why debugging is all about understanding by ams6110 on Thursday August 06, 2015 @12:08PM (#10017434)
I tried telling a client once, "if you can't tell me what you want, how am I supposed to make the computer do it." Wasn't very well received.
Re:Why debugging is all about understanding by mwcampbell on Thursday August 06, 2015 @09:10AM (#10016120)
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.
Re:Why debugging is all about understanding by userbinator on Thursday August 06, 2015 @09:20AM (#10016174)
It does get a little more difficult when execution flows into code you didn't write, but you can still validate your post/pre-conditions at those boundaries.
Re:Why debugging is all about understanding by etingel on Thursday August 06, 2015 @05:41PM (#10019653)
> In that case, my mental execution of the code will depend on a mental model of the third-party component that's probably incomplete.

That's the whole reason why you would want execute the code mentally. If you don't execute the code mentally, you might not realize that your mental model of the third-party component was incomplete to begin with. Mentally executing code is a great way to test your own assumptions.

Re:Why debugging is all about understanding by yuliyp on Friday August 07, 2015 @05:45AM (#10021629)
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 by spiralpolitik on Thursday August 06, 2015 @10:11AM (#10016506)
This scales up to about 10-15 lines of code before it becomes impractical in most modern imperative languages. Functional languages due to their higher level constructs get better mileage out of the technique but there is still a small practical limit to the technique.

It also doesn't work if your team isn't co-located.

Re:Why debugging is all about understanding by AnimalMuppet on Thursday August 06, 2015 @11:30AM (#10017132)
What? No. If you can only scale that up to 10-15 lines of imperative code, you're writing imperative code completely wrong.