I was going to title this post “I love debugging” because, well, I do love debugging code. For me that is one of the most fun puzzle solving mind challenging things someone in computing can do. This is contrary to most people I think. Beginners in their first job often feel that they are “stuck” debugging and cleaning up other people’s code when what they really want to do is write brand new code from scratch. There is where the glory is! Bah!
One of the interesting quotes in computer science is Brian Kernighan saying:
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it
The glory may be in writing original code but the difficult part is debugging. Anyone can write crappy code from scratch but it takes someone with a good brain to clean up other people’s messes. In his essay "Learnable Programming" Bret Victor early on states a truism that I think we tend to forget while teaching students.
Programming is a way of thinking, not a rote skill. Learning about "for" loops is not learning to program, any more than learning about pencils is learning to draw.
Real debugging is more than just looking for the typos and getting the syntax right. Sure that is part of it. Did someone use a “*” where they were supposed to use a “+”? Or is there a semi colon in the wrong place? These are all part of it but only a small part. Debugging requires understanding of what happened, what was supposed to happen, and what sort of things could cause the disparity. It requires understanding of a way of thinking.
We struggle teaching complete beginners because we do have to teach them a big rote skill about what a loop is and the like at the same time we are trying to teach a whole new way of thinking. This is why tools such as Alice and Scratch which avoid a lot of syntax are so popular. They let us focus more attention on the hard part – learning a way of thinking.
Getting back to debugging for a minute. I would argue that the real reason beginners should be fixing other people’s code is that doing so will help them learn more and faster how to think like a programmer. While debugging code one can look at intentions and understand what someone was thinking (or not) when the code was written. Did they take a shortcut they should not have? Did they make some incorrect assumptions? Did they just get careless? Did they forget test cases? What went wrong and how can it be fixed without creating new problems.
That fixing things without creating new problems is harder than most beginners think it is. If you are an experienced programmer you know that already but beginners need to learn that.
I wonder if what students need is to be assigned more “broken code” and be asked to fix it. It may help with the whole learning to think differently that so many struggle with. Thoughts?