4 ms·
I imagine it would be quite hard to come up with good debugging examples for a class. Anything that has one right answer is going to smell like a made-up classr
by lordnacho 10y ago
I imagine it would be quite hard to come up with good debugging examples for a class. Anything that has one right answer is going to smell like a made-up classroom assignment.
The thing that makes debugging hard is multiple hypotheses (or amazingly, exhausting all hypotheses). Your crash can be caused by errors on many different abstraction levels, so your debugging process has to be thought about on many levels. On one level, you have an illegal access via pointer. On another, you have a user whose information is incomplete.
Once you find a bug it's often hard to trace back exactly what the original state (including your state of mind) was, because you'll have taken the thing apart in various ways, added logging, looked at the call stack, memory, etc. And once you know the issue you shave down the explanation so that all those tedious steps that didn't lead to the answer seem to vanish.
One thing that got me thinking was this idea that people are expected to fail. To me, such a process is incredibly wasteful, and itself a failure. Are engineering students immune to ordinary psychology? If you tell people half of them will give up, you'll lose a lot of them, even ones who could pass.
You can make a course difficult, but don't tell people they will fail. I was never confronted with such statements, yet after my first year about 10% of the engineers had been booted due to failing exams.
His other point seems to be that courses are difficult because they aren't taught to people with the prerequisites. That should never be the case. Where I went the prereqs were a very standard set of math courses, and you could access most non-math courses knowing just those.
- majewsky 10y ago> Anything that has one right answer is going to smell like a made-up classroom assignment. If you're doing C (or any other language where that particular problem exists), it's always a nice exercise to have students write a program (or a function) that takes the radius of a circle and outputs its volume. Most students will write: double volume(double radius) { return 4 / 3 * M_PI * radius * radius * radius; } Can you see the problem? ;)
- the-dude 10y agoCircle has no volume
- noxToken 10y agoAlthough I laughed, I'm sure GP meant sphere. That is the correct formula for volume of a sphere, and a sphere is a circle in 3-space.
- the-dude 10y agoSure. But getting the spec right is more important than being smug about a silly mistake only novices make. And C has much more interesting caveats than this one.
- majewsky 10y agoAw snap. Yeah, of course I meant a sphere. (And technically, it's the other way around. A circle is the 2-dimensional special case of a (hyper)sphere.)
- julian_1 10y ago4 / 3 would be computed as an integer (eg. 1), before the result is implicitly coerced to float for the rest of the expression calculation? A nice example for debugging, and for understanding the value of languages with better typing discipline.
- yorwba 10y ago> I imagine it would be quite hard to come up with good debugging examples for a class. Anything that has one right answer is going to smell like a made-up classroom assignment. > The thing that makes debugging hard is multiple hypotheses (or amazingly, exhausting all hypotheses). You don't have to start out with an example that features all possible error conditions. It's totally fine to use a made-up classroom assignment for teaching. There is no need to put all the complexity in a single example, better to partition it into steps that can be attempted individually. Moving around in a debugger, setting breakpoints and watches, knowing where to set breakpoints and watches, tracking a value on its way through the program, adding logging to get a view of varying state over time, localizing a problem within a large code base. Those are all skills that build on top of each other, and can and should be learned over a series of successively more complex examples, each focusing on a particular aspect, while reinforcing the previous lessons. Then you can let the students loose on a wild goose chase through dozens of libraries calling into each other across language boundaries using asynchronous communication, to find the one instance where someone cast a void* to an int* to do arithmetic on it, when it should have been a float* .
- mattmanser 10y agoThese are unskilled programmers, so shouldn't it be ok to start out really simple? Have bugs with index bugs like: for(var i = 1; i < len; i++) substr(name, indexof(name, ' ')) i.e. Find out why it's not showing all the items (i = 1 instead of 0), find out what's going on with the formatting of the lastname (there's an extra space at the beginning of the name). For SQL use a JOIN where it needs a LEFT JOIN. I can think of others off the top of my head. Leave out an optional parameter that's been populated from the front-end, but don't pass it to the method call. In OO languages, have a constructor accidentally call itself instead of the alternative with more parameters (infinite loop). Nest two for loops and accidentally use i instead of j inside the inner loop. Have an if statement that looks sorta right but is logically impossible to satisfy. For the "only sometimes crashes" bugs, div by zero is an easy example. All the sort of accidents you instinctively correct now are probably good beginner debugger exercises.
- empath75 10y agoI think the problem is more general than debugging and is really just about troubleshooting in general. How do you abstract away a problem so you can individually identify and isolate the parts and test them individually? The same general techniques apply whether you're debugging a c program or repairing a car. Just on the basis of interacting with coworkers, when I see people fumbling around in the dark, it's usually just because they're not using basic troubleshooting, they're just googling (at best!) and trying random fixes in a scattershot approach. Quite a few times, I've helped people who were far more knowledgeable than me about, for example, Linux, by just asking them questions and trying different experiments to see if we could eliminate possibilities and so on. At the end of it, the problem is fixed and they thank me for the help, even though they knew everything they needed to know to fix the problem to begin with.
- i336_ 10y ago> I imagine it would be quite hard to come up with good debugging examples for a class. Here's a high-level idea that might be doable in the right circumstances. Get one or two hardware guys from an engineering company near the institution to come out with an old version of their silicon that has a fairly rapidly (but not necessarily trivially) triggerable bug. Set the system up, run over how it works, explain the ins and outs of the debug environment/setup, make the bug fire, and spend the next $class_length getting the students to try and figure the bug out. If the guys can't come back for repeat sessions, they explain it at the end. I suggest previous-gen silicon in the hope this would decrease the NDA requirement. Then again, even that may not be enough; obviously this would be CPU dependent. But even if the chip was otherwise NDA'd, if it uses a popular (or at least non-NDA'd) core and the bug is in there, that could work too - maybe you could do a partnership type thing with a custom build of the debugger that has NDA'd components hidden. Maybe you can set up VNC or RDP from student laptops back to the test setup up the front, maybe the students can just backseat-drive. But just describing this, I'm excited, I'd totally want to go to a class like this! (Which was why I tried to think of ways to get around the NDA issue)
- oshepherd 10y agoSadly, late breaking (post silicon or just late in development process) bugs aren't generally particularly more exciting in terms of debugging than earlier ones - other than the urgency/annoyance and rarity, of course. They do tend to be 10x as annoying to debug though. Not more difficult - just tedious - especially because you often end up triaging what turns out to be somebody else's bug (i.e. a checker on your block fails, so you need to trace it back to somebody else, and often they also trace it outwards to somebody else). And this is where using it as a class example gets really difficult - even people on the design team are specialists in their own blocks. Giving students all the knowledge they'd need to debug a problem would be incredibly difficult.
- noxToken 10y ago> Anything that has one right answer is going to smell like a made-up classroom assignment. It should be alright in a classroom setting. I remember one particular piece of an assignment that I received a 0 on many years ago. We were doing String manipulation, and the iterative pieces of the assignment culminated in us building a simplistic cipher. The part I did not receive credit for was recursively reversing the String. I just called the reverse method. Same result, so no harm no foul right? Wrong. The point wasn't to reverse the String so that the cipher could be created. It was to incorporate programming basics such as recursion into an assignment. It was a shoe-horned method to get us to use recursion, but it got the point across.