Live data from Hacker News

Why don't schools teach debugging? (2014)

danluu.com

121–130 of 174 posts

Re: Why don't schools teach debugging? (2014)

#121
Any school that teaches programming will take a stab at teaching debugging, although that is often limited to general familiarity with a debugger, say to the level of stepping through code and inspecting state.

The problem is that debugging is hard, and will tend to very quickly manifest any flaws in a novice's understanding. When I teach it, I describe it as a manifestation of the scientific method: observe the phenomenon (my program isn't doing what I expect), hypothesis (it might be this), experiment (if that's the problem then doing this should result in...). Repeat ad frustratum.

Unfortunately, doing that effectively required some pre-requisites: (1) An accurate mental model of how the program should behave, with sufficient detail to hypothesize about why it's not behaving that way, (2) Available tools and instrumentation that allow you to inspect a running program (I'm old enough to remember debugging by adding commands to print state to the console), (3) sufficient experience and sophisticated understanding of the system to be able to make valid hypotheses and design tests.

Only the second item easily lends itself to the classroom, and the third item is critical: After I help a student identify and isolate a bug, they often ask me how I knew what to try. The answer is, almost always, that I've seen that before. Hell, there used to be a type of memory fault in Borland C++ that I could diagnose from across the room just by the icon and size of the error dialog. (You get a lot of experience seeing error messages by teaching Freshman programming).

So, short answer, the reason we don't do a good job teaching debugging to novices is at least partly because they're not ready to learn it yet.

Re: Why don't schools teach debugging? (2014)

#122

When I was in school I showed my algorithm(on paper) to my teacher and He said: "It's wrong". I strongly said: "It works!". He froze for few seconds and than said: "Use these data for inputs" and I immediately saw the bug. Of course the entire class laughed. I know that The story isn't about debugging, but sometimes showing "right" inputs can be very efficient way how to explain the bug to other person.

"froze" implied he was scared. try "paused" or "ruminated" instead.

I donno, when I see code that works and I don't know why I get plenty scared.

Re: Why don't schools teach debugging? (2014)

#123

> the problems were caused by not having an intuitive understanding of, for example, the difference between f(x+a) and f(x)+a Does the author really advocate that the instructor of advanced college course needs to spend his time on explaining the difference between f(x+a) and f(x)+a to his students? I don't have any idea how someone with such an understanding of algebra could even get into a college even if he wanted…

What kind of middle school did you go to????

I have to admit, I changed several math-oriented schools - but trigonometry is supposed to be standard middle school subject, no? If you don't understand the difference between sin(x) + y and sin(x + y), I can't imagine you can pass a simplest high school entrance exam.

But I guess it depends on the country. US math education, from what I hear, never ceases to amaze me - the contrast between the abysmal level of your schools and the best CS departments in the world is just astonishing.

Re: Why don't schools teach debugging? (2014)

#124

In school, you're always told to show your work. I'm sure a lot of us here tended to be among the smartest in your class, at least before university, and we often thought having to show our work was silly. That's why a lot of us get tripped up when it comes to the type of debugging the author is talking about (it certainly still happens to me sometimes). Showing our work reminds us that solving problems is an iterati…

When I was attending Harvey Mudd College I worked on an engineering clinic team with a significant software component and was shocked to find that none of my teammates knew how to use an interactive debugger. This really slowed the team down and made the work far harder than it needed to be. At the end of the project I wrote a letter to the department head suggesting that they add a unit on debugging to the core curriculum. But I don't know if they ever acted on it.

Re: Why don't schools teach debugging? (2014)

#125

I think the Feynman Method is equally applicable to debugging; I've also done some teaching before, and seen far too many beginners open the debugger at the first bug they find and start stepping aimlessly through the code, seemingly unaware of what their code should be doing. They eventually reach the point where the program outputs the wrong result, and have no better understanding of what they did wrong, because t…

I completely agree. In fact, I think running a debugger should never be the first option. My process:

1. Read the code and think about what it's really doing.

2. If that leads nowhere, write (more?) unit/integration tests.

3. Only if the above two fail, run the debugger.

"Contemplating" code has another benefit: since you're looking at the whole picture rather than jumping line-by-line it develops your intuition about why things fail.

Re: Why don't schools teach debugging? (2014)

#126

> the problems were caused by not having an intuitive understanding of, for example, the difference between f(x+a) and f(x)+a Does the author really advocate that the instructor of advanced college course needs to spend his time on explaining the difference between f(x+a) and f(x)+a to his students? I don't have any idea how someone with such an understanding of algebra could even get into a college even if he wanted…

>I don't have any idea how someone with such an understanding of algebra could even get into a college even if he wanted to learn humanities. Schools' income depends on the number of students (either a budget allocated according to student population, or students paying directly). Therefore, the incentive is to delay failing people as long as possible, as long as it doesn't affect the quality of the graduates.

But the quality of a school depends on quality of students.

In two ways, even: first, if you select good students, they show good test results and place good jobs anyway, because they're smart. But also (and this is most important for me as a potential student) your school's _product_ is not only interaction with instructors, but also interactions with other students. The better your peers, the better education you get - even if you disregard the "school network" factor.

Re: Why don't schools teach debugging? (2014)

#127
post #95

It is a task that shouldn't be learned in university but in middle school. And it's not just useful to stem, it's useful to many things in life. E.g. a disagreement between two educated, smart people usually can be resolved by debugging how everybody got to their point of view and then flashing out the details. It's also how you figure out why the toaster isn't working any more, or why your wife left you. It's also a…

Your comment couldn't be more on point. I viscerally disagree with the direction that a lot of "coding" initiatives are taking in schools nowadays. The claim is that the intentional move away from actual computer science is that it is a way to attract more people.

Fine. But when the course is just about making "whatever you want," then that really valuable time of learning these debugging skills gets missed, 'cause you can always pivot and do something else. The most valuable lessons I've learned about coding -- and the ones which, like you wisely stated, are applicable elsewhere in life -- had everything to do with needing to work through a tough computational challenge.

That taught me how to know I don't know something, how to poke at an issue in such a way as it would reveal something about the system (or my own understanding), the oh-so-currently-hyped skill called "grit", etc.

Every thinker or scientist I deeply respect has a treasure trove of examples of being stuck and working through hard and challenging problems even as little kids. That somehow we think an avenue for a more educated populous consists of presenting fewer experiences like that to youngsters is beyond me.

Re: Why don't schools teach debugging? (2014)

#128
post #2

Profusely agree with the author. As someone who switched into CS from the humanities, one of the biggest challenges for me was less about syntax and more about figuring out the errors in my logic. For some reason though the former seems to get more focus by professors. "We excitedly explained our newly discovered technique to those around us, walking them through a couple steps. No one had trouble; not even people wh…

> A number of people resolved to restart from scratch; they decided to work in pairs to check each other’s work.

Everywhere I've studied, that alone would have counted as academic dishonesty. If it wasn't an explicit group project, there was clear language about working independently; you couldn't just decide to pair up. Almost everyone, even my graduating class's valedictorian, did it anyway. I was the honest chump and my GPA suffered in comparison.

Discussion of the problem definition was condoned, but any talk about solutions was off-limits. Many professors would include homework sets with a final question asking you to confirm that you worked alone and received no help outside the professor or TA. Some allowed you to admit to receiving help, with no punishment beyond 0 points for the assignment.

I shall assume this guy had an atypically lenient professor for his first engineering class.

Re: Why don't schools teach debugging? (2014)

#129
post #76

Earlier quoted context omitted.

Which is so odd to me because the JavaScript debug tools are some of the most complete and easiest to use. They're right there!

But I can't get them to integrate well with my dev tools. If, for example, I'm using something like babel/webpack/Typescript there is no easy way that I've found to for example just set breakpoint on a line of code in my editor/IDE and have the web browser debugger break when it gets there.

VSCode provides this functionality(https://code.visualstudio.com/docs/editor/debugging).

Re: Why don't schools teach debugging? (2014)

#130

Any school that teaches programming will take a stab at teaching debugging, although that is often limited to general familiarity with a debugger, say to the level of stepping through code and inspecting state. The problem is that debugging is hard , and will tend to very quickly manifest any flaws in a novice's understanding. When I teach it, I describe it as a manifestation of the scientific method: observe the phe…

I absolutely agree with the pre-requisites --

"(1) An accurate mental model of how the program should behave, with sufficient detail to hypothesize about why it's not behaving that way" -- While working as a firmware engineer, I once got a bug from a customer, he reported that they were in Argentina and the device with the firmware would lose an hour in the time displayed every time they had a power loss and that the problem goes away when they put the time-zone to Brazil, this much was enough to know that the problem was with the day light saving time part of code. Some engineer hypothesized that problem might be with the NTP server but his hypothesis was wrong because NTP server was dealing in UTC.

"(2) Available tools and instrumentation that allow you to inspect a running program (I'm old enough to remember debugging by adding commands to print state to the console)" -- I dealt with code which installs the firmware, frequent power cycles made keeping a debugger attached an exercise in futility so I just continuously logged the top two frames of the stack by using a system call. Crude way to trace the control flow but helped me in understanding the installation process a lot.

"(3) sufficient experience and sophisticated understanding of the system to be able to make valid hypotheses and design tests." -- This was even more important while dealing with firmware hangs, dealing with hangs made dealing with crashes look easy. Crashes were the messy criminals leaving a lot of clues behind. Hangs are the type of criminals who would have to be caught while committing the crime.

I would also like to add one more --

"(4) When debuggers fail you, git-bisect is your only true friend." -- I once was dealing with a memory corruption bug, in a piece of memory which was shared by two systems, the number of processes with access to that piece of memory was bonkers. I decided to brute-force my way out, it worked in the last release, it stopped working this release, I just kept doing a git-bisect between clean and dirty states and found the code which caused the bug. This way was definitely not the clever way to do it, but brute-force is sometimes the only option left.

Post reply on HN