Skip to content

Coding in math class: comparing programming and problem solving

January 22, 2019

As I’ve mentioned previously, most of the focus of my sabbatical in Norway is working with faculty at the University of Oslo to help prepare middle and high school teachers for a National curriculum revision in Norway that will require math teachers to incorporate programming into the math curriculum at all levels in grades 1-13. As part of that work, I’ve now gotten to visit a number of Norwegian schools and see some of the early efforts at incorporating programming into the maths curriculum.

Overall, I’m deeply impressed by what I’ve been seeing. The government of Norway is making a serious commitment to funding professional development for teachers, and the effort to bring about this change in the curriculum is strongly focused on giving students another tool to explore and think mathematics rather than just “preparing students for future careers.” The Norwegian teachers I’ve met are also very enthusiastic about the possibilities and opportunities to improve the Norwegian math curriculum to incorporate more problem solving and inquiry based learning.

I’ve also see that Norwegian classes and schools are quite varied. The Norwegian educational system is founded on national commitment to equitable school funding that would be unheard of in the States, it even goes so far as to provide additional funding for schools that have large populations of at-risk students, and as a result every school I’ve been visited is beautiful and fully stocked with all the furnishings, equipment and resources one could imagine needing to teach a great physics or math class. At the same time, I’ve sat in on math class ranging in size from 7 students to 39, and I’ve been thinking a lot lately about how you teach programming to students in such varied environments.

Here’s something I seen in my own teaching of computer science that I find to be particularly challenging—namely how to manage large classes when students are working individually or in small groups and each student/group is in need of assistance from the teacher. Teaching programming in a math class seems to exacerbate this, since students aren’t seeing programming every day, and students are likely to have a wide range of programming backgrounds—some are quite experienced and can often race through an assignment that a novice will struggle with. What often results is every student getting stuck on their own individual problem, and needing the attention of the teacher to help debug. The bugs students encounter, particularly when they are typing their own code from scratch, run the gamut, and I’ve found most beginning students are unable or very reluctant to interpret the error messages or do much troubleshooting on their own. So what happens is you as a teacher are faced with a 20 or so students, intermittently calling for help with problems that you have to diagnose and help solve on the spot, and while your attention is focused on one student or group, the other students who are waiting are steadily growing more frustrated.

I want to think for a moment about similar spaces and classes where this doesn’t happen. The first thing I think of is many of the math classes at my school that focus on Exeter-style problem solving. Here, students are working in groups of 3 or 4 every day on challenging problems that are often beyond their individual reach. It’s not uncommon for students to be working on problems at the whiteboard in these small groups for nearly the entire class, with the teacher just walking around and checking in on each group throughout the class. Students still get stuck here, but it’s rare to see moments where an entire group can’t make progress and is calling for the teacher to intervene.

I’m curious about this difference. I think it’s true that problem solving in math and programming often provide equal levels of challenge to students, but in my experience, students I’ve taught have a much better sense of WDYDWYDKWTD (What Do You Do When You Don’t Know What To Do) when they are problem solving math class as opposed to programming. I think there are lots of reasons for this, and I’m sure the fact that problem solving sits at the hear of our math curriculum, and teachers spend a lot of time helping students to develop these WDYDWYDKWTD skills, and it’s clear those skills don’t transfer to programming when you’re faced with some sort of seemingly indecipherable error message.

This makes me think that even if programming is an topic that is occasionally interwoven into a math class, it would be helpful to spend some time explicitly teaching students many of the skills that are helpful for debugging—running your program often, interpreting error messages, learning to add print statements and comment out blocks of code to localize bugs, and all the other things we teach in computer science classes that help students to become more comfortable with debugging their own code. Of course this takes time and practice—students often don’t pick up these habits until they’ve really struggled to get a program or two working, and I’m not sure how you fit all this into a math class that already has a lot of content to cover.

But my experiences thus far make me worried for the teacher of 30+ students in a math class who is trying to get their students to do some sort of programming activity that asks for students to work independently in class. What sort of structures or activities could a teacher put in place that don’t consume too much time but could help students be better at troubleshooting their own code?

14 Comments leave one →
  1. January 22, 2019 8:59 am

    You are describing my class precisely, but I think you likely know this struck a chord with me.

    I haven’t come up with a good answer for managing the multiple errors on the spot. Students aren’t developed enough in their skills to deal with many of the issues they are addressing. What I’ve had to do is try to train them, as soon as they get to one of these spots, to identify what change they made to their program that led to the crazy/confusing behavior.

    My response is to take some time to think about it, and then by the next class, have an example of code that either solves the problem or does what they were trying to do correctly, but in a slightly modified context. This means I am solving the problem generally, but not their problem specifically. I also put in a generous amount of comments that they hopefully read.

    That said, things still aren’t how I like it. It could be a year (or five) before I get to that point.

    • January 22, 2019 5:12 pm

      Yeah—I think this must be especially true in your app development class where students are working with learning swift sometimes from no background. Yet, when I observed your class, you were far from where I’ve been where I think I’m ping-ponging from fire to fire and no one is getting anything done without me looking over their shoulder.

      It makes me think that students in CS almost need some frequent guided exposure to these points of frustration/being stuck. I know there’s some research basis on this being the point of livecoding, where you’re trying to program a thing and work thorough it in front of the class and debug on the fly.

      One of the things I often see is students really think they should program almost like they write—write a full draft, and then re-read it to look for errors, and usually, for beginning programmers, this is a recipe for disaster, they wind up with a litnay of error messages that will take the rest of the day to untangle. I’ve often tried telling my students to run their code statement by statemnt, but they never seem to take that advice to heart and do it, since beginning programms seem so “simple.” Maybe I should have them spend more time just typing commands into the python interpreter directly?

  2. January 22, 2019 10:31 am

    I’m fascinated with the idea of practical coding in math and science classes. I introduce students to MATLAB / Octave whenever we cover anything linear algebra related, and last year I asked students to work on CodeAcademy if they ever finished early in Precalculus. They were able to do some fun assignments later in the year.

    I think the best advice I’ve received and experienced is: don’t teach computer science at the same time as another topic. It’s cognitive overload and tends to do more harm than good. Instead, as you suggested above, coding and debugging need to be taught explicitly and separately from other topics. In an ideal scenario, which it sounds like is being developed in Norway, students will develop coding as a tool that becomes more sophisticated as they work through higher levels of math and science. Non-computer science courses shouldn’t really expect computer science proficiency, but when they do, it should be the most basic of basic skills. Don’t even think about loops.

    A great way to learn a language is to start with syntax and debugging! When I introduce MATLAB / Octave, I demonstrate the syntax for entering matrices and vectors and then have students practice fixing broken code. Importantly, they will have done several days worth of work with matrices beforehand, so they are already familiar with the math.

    Students are going to come across a lot of the problems that you hinted at above, so it’s nice to preempt any issues you can predict. With matrix-vector operations, students are going to have dimension mismatching, so show them the error they will see when they leave out an element or try to multiply a matrix by a row vector. Then show them how to interpret the error and correct it. If they are using limited operations, there are limited errors that they are likely to come across.

    Also as you hinted at above, students aren’t familiar with run-time errors so they simply don’t know to read the error. It seems so simple, but they are accustom to ignoring large amounts of text every day (thanks, Internet), so they won’t automatically read even the most helpful of error messages. You have to run a script with an error, then prompt them to read the error and ask for suggestions to correct it.

    • January 22, 2019 5:18 pm

      These are great points. I think it’s true that the Norwegian approach to incorporating programming into math is doing it’s best not to conflate the two. Students learn all about quadratics and then write a program to tell ask the user for the a, b, and c term of a quadratic euqation and then the program prints whether it has 0, 1 or 2 solutions for instance.

      Your comment also makes me think students need to do more with scaffolded code. I think we often think that some of these programs are so small students should write them from scratch, but the cognitive load of remembering syntax while trying to write mathematical concepts into code often proves overwhelming and has students producing gibberish code. I think students would be far less frustrated if asked them to add an important line to a working program, or gave them a program with a single syntax error, like unmatched braces and ask them to find it (this one is particularly hard for kids since the error is usually in the line before the error message).

  3. gcschmit permalink
    January 22, 2019 11:04 am

    We have seen similar challenges in our computer science classes; especially, in our intro class. Pair programming certainly helps in much the same way as the Exeter-style problem solving that you describe. In addition, we encourage students to help each other even when not pair programming. Last semester, we realized that students need more support than the informal coaching they would get from us throughout the course. We developed a Coaching Card for our Python-based intro course as well as APCSA. The card somewhat enumerates the WDYDWYDKWTD strategies in the context of different activities and computational thinking pillars. While the original intention was that this card would be used by a student coaching another student, we later realized that this card is a good resource for a student who wants to work through the challenge on their own first and needs to be reminded of these strategies.

    • January 22, 2019 5:24 pm

      I saw and loved this card when you posted it on twitter and think it is perfect for CS studnets, but it probably isn’t enough for the students who are trying to learn programming as part of a math class, and as a result see programming infrequently. Today, I saw some 13 year old students trying to write a program that ask the user for a number of Norwegian Kroner and convert it to Euros, and they were getting wrapped up in all sorts of errors—not understanding that input is a function with a return value that must be stored in a variable, not understanding how/why to cast that variable as a float, etc. I think we could have set things up better by first asking them to write out psuedocode, but I don’t think anyone would have really struggled with that task. They all knew what they needed to do, they just didn’t remember the specific syntax they needed and the details of that syntax (i.e. that input returns a string, or in some cases, what a string is).

      Maybe it would help if students in this situation had a very simplified reference card that showed them things like this? In previous assignments, we’ve given them analagous programs, and that hasn’t really helped their understandging. I’m thinking they need some sort of stack-overflow lite, that has questions like “how do I ask the user for input?” and easily readable responses. What do you think, Geoff?

      • gcschmit permalink
        January 23, 2019 9:21 am

        I think a reference card could be very useful. Personally, I rely on something similar when writing code in a language that I haven’t used for a while. For example, if I need to write something in Perl, I reach for O’Reilly’s Perl Cookbook. Their cookbooks contain snippets for common operations in that language. You wouldn’t want something as detailed as these books, but perhaps a simplified version of those recipes most appropriate for the code students will write in your class.

  4. January 22, 2019 12:28 pm

    I face a similar problem teaching electronics to a class of 80 (80 in lecture, two sections of 40 in lab). I’ve tried to capture the essence of debugging in Chapter 13 of my book, but that chapter probably needs more work. The debugging techniques for programs and electronics are similar, but not completely identical (mainly because in electronics there are a lot more places where the”correct” notional model can be inaccurate).

    • January 22, 2019 5:26 pm

      This is a great point. Do you ever set up exercises/experiences for them that they specifically need to debug? Starting with something simple, like just disconnecting one of the oscilloscope leads?

      • January 23, 2019 8:57 pm

        I have not done specific debugging exercises, though I have added some exercises to prepare them better (like one giving them a schematic and asking them to color-code the wires, and another asking them to draw a block diagram from the schematics). The problem with artificial exercises is that they often bear no resemblance to the real debugging, because it is so hard to anticipate what mistakes students will make.

        Leaving off an oscilloscope lead is not a very common mistake, but being off by one row in wiring a breadboard is. The simple, anticipated mistakes are pretty easy to guide students through, but many of the mistakes are one-of-a-kind ones that I have never seen before, and real debugging techniques are needed.

  5. January 22, 2019 6:53 pm

    Just came across this awesome post, and it has a lot of good ideas for setting norms for different types of collaborative programming: Promoting collaboration in a computer science classroom

    • gcschmit permalink
      January 23, 2019 9:26 am

      I think the “mob programming” described in this post may be an opportunities for the teacher to model best practices. For example, incremental development could be modeled by running the code after just a few students contribute lines.

  6. January 23, 2019 5:30 am

    Two great responses from Brian Carpenter on twitter

    I really like the second idea, and wonder about creating a structure in class where we pause the class at various instances and everyone has to get to a running program the next minute, and then we share what a few students had to do to debug their code.

    • gcschmit permalink
      January 23, 2019 9:31 am

      I don’t know if these activities would translate from the CS classroom to the math classroom, but we do an activity where students are directly to purposefully introduce bugs into their program and then capture the errors that are generated. The goal is that when students later see these errors, they are familiar and have a mapping from the error back to the bug.

      A second activity we do is when I provide code to the students that has a few bugs, and they have to find and fix the bugs. This gives them focused practice on debugging and somehow the dynamic is different when they are finding and fixing my bugs instead of their own.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: