Friday, October 19, 2012

Automated Exercises for Code Tracing

One of my goals for my courses is to have students do a lot more exercises. I am already putting up videos to go along with the book material, but students need to apply what they watch. (There also needs to be a way to enforce that they watch/read things.) For writing code this isn't all that complex other than having a tool to do it. I have been planning to write such a tool. There are other tools that do this as well, but I don't know of any that use Scala. I want to write something that is language independent so that I can use it across all of my classes.

I also value having students trace code. Of course, if I just show students code and ask them what it evaluates to/prints when they are in their room, they can simply type it in and run it. That doesn't benefit them or force them to work on the skills I want them to develop. This post describes an idea I had in regards to this. If anyone happens to read this who writes CS educational tools, feel free to take the idea and implement it yourself. Part of the motivation for this idea came from the stack trace display in DrRacket.

The basic idea is that you have students indicate where the flow of control goes and possibly have them enter values for variables along the way. The goal is to force them to actually demonstrate that they followed the code. That way, even if they do type it in and run it, they still have to think things through.

The figure below shows a mock-up of what the simplest interface might look like. The instructor would provide the code and the student has to click on each line in the order that control passes through them. Not only does this force the student to think through what is happening, it can be verified automatically so that students can be told if they have the proper trace without taking additional instructor time. That is essential if you actually want to use this to force students to do things in a real setting.

The figure above is a rather minimal example of tracing as it only follows the control flow. For some problems this might be sufficient for demonstrating that the student knows what is going on. However, for many problems it would be advantageous to have the student also track values attached to names/variables. The figure below shows a very ugly, first draft of what such an interface might look like. This is something that would need a lot more interface work, but the idea is to show the same control flow information, but also have tables that show the values of variables and how they have changed over time.
This would work for recursive functions too. As shown here, you have a table with a large column for each variable/name. You could also have separate tables for the different stack frames. I can also picture a more dynamic representation where there is only one row drawn for each stack frame, and the program records the values in that for each step in the computation. Then the student or someone else looking at what the student did could select an arrow to see the value of the stack frame at that time.

Does anyone know of tools like this? Would anyone be interested in having something like this? Personally, I really like to get students to trace through code and I can't do nearly enough of it. I feel that a tool like this could be very beneficial in the CS1 setting and even in some parts of CS2 and Data Structures.

No comments:

Post a Comment