Friday, March 22, 2019

Debugging Student Code for Fun and Learning

Students are really good at creating strange hard to solve bugs in their code. I am convinced that the code of a raw beginner can easily be harder to debug than that of a professional coder.

I had a couple of good ones today. One was actually pretty easy once I realized the cause. I have some international students. Great kids, very smart, hard workers. English is not their first language though. In fact, English letters are not their first character set. In one class I have boys from Cambodia and Viet Nam. The character sets they grew up with are very different from English characters. This means that sometimes English characters confuse them. l, I and 1 can all look alike to them especially in some fonts. Like this one. So I had some non obvious "spelling errors." They and I have a better idea of what to look for next time.

The other one was harder. We’re using C# and Windows Forms. Now normally this makes things easy. But you can also cause some very puzzling errors. In this case, the code seemed to be doing everything it was supposed to do EXCEPT showing the results in a list box. I tried a lot of my bag of tricks. Single stepping through code, displaying intermediate results (that didn’t work because nothing was displaying in the list box). I copied the code into a new project. I created new objects. I tried a lot of things.

Finally, I did a side by side comparison with a project that worked and that showed me the problem. For the curious, Windows Forms projects run a subroutine to initialize and instantiate the objects on the form. Some how, probably a copy paste error, this student was calling it twice. Without going into detail, this resulted in two sets of objects with one of them covering the set that was actually being acted upon for the display.

I try to look on the bright side of things. In this case, I have new things to look for that I didn’t have before, I have gained insight into issues that my international students have (and may change some variable names I use), and I got to demonstrate debugging techniques to some students. That’s a win right?


Garth said...

This is why we make the big bucks.

Alfred Thompson said...

Actually this is why our students thing we're so smart. Smarter than we are.

Unknown said...

Well said! My most common error this year is semicolons after if and for statements. When I see things like this I always wonder if I taught something different or not as well this time. But you did inspire me. I need to have my student aide make a poster for this when I get back after spring break!

Alfred Thompson said...

I'd love to see the poster you come up with. Semi-colons after if and for statements are something I am seeing more this year than in the past. I wish I could figure out why.

Brett Becker said...

Here are two of my favorites. The second one was student generated.