Wednesday, February 27, 2008

Teaching Programming

We started the programming unit yesterday.

This year I'm switching from Perl to Python. I'm also hugely overhauling my teaching style. I was convinced by Vern Ceder (and various other sources, I'm sure) to get to graphics as fast as possible and skip the endless pedantic slog between here and there. In nearly all of the books I have used as resources, graphics are late, late, late. I decided to take a page out of the media computation book (not literally, but mostly only because I don't have a copy), introduce graphics as fast as I can and do lots of Just In Time teaching to backfill what students need as they care about it.

I want to mention my incredible gratitude and luck at the support I've received. Vern's presentation at NECC 2007 was transformative in my thinking about this unit. Getting to participate in the Chapman University workshop about teaching Python gave me the basics of the language. And most amazing, I have been meeting with Guido van Rossum regularly this fall and winter. He has reviewed my code, explained concepts without demeaning my lack of knowledge, and regularly reminded me what beginning programmers are like when I waver about presenting the material in this unusual, out-of-order way. He might be the nicest super-geek I've ever met, though Tom Zeller is right up there.

Day one went great! I started the students out in IDLE in interactive mode. We walked through print statements with strings and then numbers. It was great - the kids let right to the places I wanted to go, like learning about a syntax error when
didn't work the way they thought it should and testing what happens when you put math into quotes. I introduced variables super-quickly - in the past, variables would have taken an entire period, this time it was almost an aside, as a way to do math. Similarly, I introduced for loops and the range() function in about 3 minutes because I was up against the end of the period. The kids followed pretty well. I stopped to check the comprehension level several times and while it was slightly overwhelming, they were fitting it together pretty well. One thing that went very well was that I'd grabbed a few photocopies of their math textbook so I could show them how to use Python to program some of the problems they would face later that day in class. The whole concept of working collaboratively with other teachers is the subject of another post, but I was very happy at drawing the connection.

There were a bunch of things that went really well. It was very interactive, the kids were engaged, and they were typing right along with me. I think they really got that you can (and should) create hypotheses and test them right away. "What if you do blah?" "Let's try it" "Oh, cool!" They had terrific ideas and were able to figure things out really fast.

There were a few things that were, um, sub-optimal. For one, I had planned WAY more than I could reasonably teach in one period and didn't cut myself off fast enough - I was too excited about the connection to math. I would have liked to have given the students a small homework assignment to write a program and didn't have time to do so. I'm okay with it since not having homework makes the students happy and I'd like them to think programming is fun. Yeah, not optimal, but I'm looking for the silver lining.

Second, the Just In Time teaching requires the teacher to be flexible and able to quickly analyze situations to figure out what is going on and what is worth covering. Some of the time that worked well - on the fly I decided not to cover modulus and the sqrt() function in the math module. Some of the time it didn't work well. Their math problem was to determine five values of x that would make 2x-6>=3 true. I showed them how to do it but then was preparing to segue them out of interactive mode and into script mode since it had to happen 5 times. (This was also where loops came in, even though it meant skipping conditionals!) In one class, a student suggested just programming y=2*x-6>=3 and then iteratively changing x and re-evaluating y. Which, of course, didn't work right, but on my feet I couldn't remember that it was because y had been set by what the formula evaluated to in that moment. Duh. It wasn't horrible, but I should have known better.

Tomorrow I will show them two longer programs - one that is a "guess a number" game (binary search!) and one that generates Shakespearean insults. Then they'll be on their own to write a little program. So exciting!