Live data from Hacker News

Why Don't Schools Teach Debugging?

danluu.com

1–10 of 132 posts

Re: Why Don't Schools Teach Debugging?

#2
Yeah there are two fundamental things that are not taught well in many (not all) computer science programs.

1. Debugging as the author explains.

2. How to properly use version control and work with others using version control on the same codebase. Hopefully Github for education will help with this one.

Re: Why Don't Schools Teach Debugging?

#3
It's more like they don't teach general diagnosing/understanding why things don't work. I consider the skills needed to debug a computer program, to diagnose a hardware problem, to fix a car, and to fix commercial coffee brewers to be almost identical (and I have done all of these things, a lot). In fixing a computer, you have a mental checklist of all of the things that could contribute to it (failing hard drive, bad termination, failing memory, loose cable). In fixing an engine, you think of what the problem is (rough idle), what can cause it (plugged fuel injectors, vacuum leak, exhaust leak), and slowly determine which one is the culprit (probably not the fuel system, goes just fine 75 down the freeway. Oh, that vacuum line is disintegrating. Good job, Toyota).

They all follow a similar pattern of identifying what the problem is, what physical manifestations can actually cause that problem, and then eliminating them one by one. This involves looking at the whole picture to narrow it down. This is not something I learned in school, I just figured it out growing up. I've found friends that don't necessarily know anything about computers, but are mechanically inclined, think similarly to how I do. I do have an innate desire to understand how everything works, and this definitely helps me understand what can physically cause the problem. That said, I did just take an Intro to Math Thought, for my math degree, and while it didn't really teach problem solving as I described above, it dramatically improved the way I thought about proving things rigorously.

Re: Why Don't Schools Teach Debugging?

#5
The best way to find the source of a problem can be summed up in two words: binary search. On the other hand, having witnessed humans physically search for things in ordered collections, it seems we're instinctively programmed to perform a linear search.

Re: Why Don't Schools Teach Debugging?

#6
I really enjoyed this post having attended the same school and taken some of the same classes. I'm actually currently in my final months of a mechanical engineering B.S. at Madison, and I think the problem goes beyond a "hazing" of freshmen.

For me, my ECE 352 was Introduction to Dynamic Systems. For anyone here without a physics background, it's basically an introduction to "more real" mathematical modeling of physical systems, beyond what you would learn in your first few semesters of college physics. Think "applied differential equations."

This class naturally involved some fairly high level math compared to what we had been using before, and I think the professors honestly didn't know (or had forgotten) how to transition into it. Suddenly the class was using things that they might have done one or two homework assignments on in differential calculus a year a go, but there was never any "here are the overarching concepts used in this class and how they fit into the two years of calculus you have already taken." The class was just dumped off the Laplace transform deep end and left to memorize steps to solve problems.

I think the problem was that the professor had honestly forgotten what it was like to not have an intuitive grasp of what a Laplace transform did or how to linearize a dynamic system. I've found myself falling into almost the exact same trap when teaching people object oriented programming for example. To an experienced programmer, an object is the most natural thing in the world, you can pass them around, perform operations on them and they just "work" for you. It's so simple for you that it's hard to remember that it may be a completely foreign concept to someone brand new.

The thing is, it's comparatively easy to just teach someone the steps to solve a specific problem when the alternative is teaching them to think in such a way that they could solve it on their own. It's the same with debugging, it's the same with math, and with programming. I spent the rest of that semester watching the professor spend every single lecture doing one or two difficult examples, and nothing else. Teaching someone so that they can gain a deep understanding of a given subject is really hard, and I think it's the rare school and professor that can do it effectively.

I ended up doing well in that class, but it was really by rote memorization of every single mathematical "scenario" that I thought likely to be on the exams. It wasn't until a year or so later that dynamic systems finally clicked into place, and it was because a professor in an unrelated class happened to spend 45 minutes on a good intuitive explanation of what they meant.

I think teaching real systematic debugging is similar in that it's something that requires a real mental investment on the part of the teacher. That's not to say it's impossible, because it certainly isn't. It just requires someone to make the investment and explain the why as well as the how.

Re: Why Don't Schools Teach Debugging?

#7
I did an electrical engineering course. Especially with hardware ("welcome to tweak week"), there was a real sink or swim approach. I ended up feeling like it had to do with testability. It's easy to grade a test if you just look for right answers, and mark everything else off. It's easy to grade labs if you just look for the circuit tracking the input frequency. Grading either based on some assessment of how well the student understands what's actually happening is much, much harder.

My older brother and I went through the same classes and labs together. He brought to the table 15 years of experience playing around with electronics, so when we took labs, he had a clear sense of how to debug hardware.

He would wave his hand over some part of the circuit, and make gnomic pronouncements like, "When the input goes over about 5 volts, this part goes apeshit and starts firing back at it." Then he'd swap out a cap or a resistor, and everything would start working. I just went along for the ride.

I had decent math skills, so I did all right in the program. But I never learned that intuitive, heuristic, holistic way of grokking circuits like my brother did. Nor could I ever see that the school had any way to reward people like him, who "got" things at a deep level.

My sense was always that his approach didn't test well. If you test people for calculating the right voltage, you end up rewarding people who "plug & chug" quickly, even if they don't know what the voltage means, or why it would make some cluster of components go apeshit when it goes over about five volts.

Re: Why Don't Schools Teach Debugging?

#9
Ability to debug is really a function of general domain knowledge, "skill" of accessing documentation and/or examples, and good understanding of experimentation. It's difficult to teach, as different coders approach problems in different ways. First, I'll explain what I think makes one good at debugging:

1. Domain knowledge, which I'll consider code that the programmer has either written herself or has otherwise become intimately familiar with, cannot really be taught. But you can at least prepare a bit so you don't get lost in the woods. I think it's good practise to understand the basic file structure of what your working on and, generally, what is in the files you might be working with. More detailed knowledge of code will come through being able to trace data through files. This is not trivial in larger code bases, again, I recommend using notes or whiteboards. This is necessarily lower when you first encounter significant code that is not your own, and people who can leverage their other skills tend to do better before acquiring knowledge of the surrounding code.

2. I say "skill" at finding documentation in quotes because sometimes, good documentation does not exist. But the only way to increase your knowledge of what's happening in your programs is to start figuring out what the components you are using. Generally, newer programmers tend to find that the code they are writing doesn't operate the way they hope because they have made a mistake in arguments or syntax. Examples really help alleviate this. I'm not certain this can be taught very well except for pointing students towards documentation, but good debuggers tend to understand the benefit innately before too long.

3. If you're having problems with code that you think should be working, you need to be tracing data. At each step, you should know what your variables are and what you expect them to be. This is not trivial, and it can be very difficult to determine just where something is going wrong. But this is also the heart of debugging: being able to figure out where your signals are getting turned around.

When you have nothing else, you can just start testing components for correctness and model a cull cycle of your algorithms. I don't think this can be taught, because many bugs are not like one another. After time, you might grow to recognise code that would more probably produce bugs, but I don't think there is a teachable process for finding bugs. Sometimes, things just be broke. But knowing the manner in which things fail, you can find solutions that bypass the sorts of code that cause errors. I'm not saying this is easy, but I'm saying that it's something that you kind of need to learn for yourself.

Re: Why Don't Schools Teach Debugging?

#10
Engineering programs are designed to weed people out and give the ones who stay the ability to teach themselves new things. Debugging is an example of one of those new things. If you go to school and have your hand held through the entire process you won't be very well equipped to function in the real world where it truly can be sink or swim.

My Chemical Engineering program was designed around the approach of "give the students homework with no instruction and review the problem sets after they are due". This was tough to handle and weeded a lot of people out every semester yet was a great introduction to working in the real world where a lot of times you have to figure out complex situations with little to no help from anyone else.

Post reply on HN