## Archive for July 5, 2009

### How high school students start thinking about code

My colleague Amy Bruckman and her student Betsy diSalvo have a really great project going on this summer, called Glitch.  Betsy is interested in how African-American males engage with technology and why so few pursue computing as a career.  She notes that African-American males play video games more than any other gender-ethnicity demographic groups, and yet are one of the most under-represented groups in computing majors and careers.  To address this discrepancy, Betsy and Amy are training a group of African-American teen age boys to be game testers, and in so doing, getting them to engage with how the games they love are built.

Amy and Betsy are teamed up with Dr. Charles Meadows of Morehouse College, who is teaching the teenagers how to program in Alice.  Betsy wanted them to see some textual code, too, to get them to see how programs like their games are created.  I agreed to teach a few sessions of Alice + Media Computation (like at the Tea Party site) being developed by Barb Ericson, Wanda Dann, and Steve Cooper.  That way, they’d be learning a bit of textual code to work with their Alice worlds.  I decided to do it with Python, so that there’d be less overhead than Java.  (My slides are available, if you’re interested.)

I’ve found it fascinating to work with the Glitch guys.  It’s been many years since I’ve taught high school students, and rarely in a situation with a small number of students.  I get the chance to see what they’re struggling with, and how they tackle problems.  I’m learning a lot about how these students think about code.

They got the idea early on that they can change constants in programs, and things generally keep working, though sometimes in new ways.  One of the students took our function to generate a negative of an image and started changing constants, like this:

```def negative(picture):
for p in getPixels(picture):
r = getRed(p)
b = getBlue(p)
g = getGreen(p)
#Original: color = makeColor(255-r, 255-g, 255-b)
color = makeColor(20-r, 5-g, 100-b)
setColor(p,color)```

The result was really interesting. Because the values for red, green, and blue were clamped at 0, the effect was to posterize the image.  Bright colors emerged, and the number of colors were reduced.  I don’t think the student who invented this really understood what he was doing.  It was a positive outcome that rewarded tinkering, poking-around.

Another one of the students wanted to write a function to make an image completely black.  What he wrote was absolutely amazing to me.

```def makeBlack(picture):
for p in getPixels(picture):
r = getRed(p)
b = getBlue(p)
g = getGreen(p)
#Original: color = makeColor(255-r, 255-g, 255-b)
color = makeColor(0=r, 0=g, 0=b)
setColor(p,color)```

I asked him to explain what he was doing.  Here’s how I think he understood his program.  He saw the variables r, g, and b as defining a relationship — that r would represent the red channel for the pixel, so changing r would change the pixel’s red value.  He saw 0=r as setting the red value to zero.  Why didn’t he write “r=0“?  He hadn’t quite internalized left-hand side vs. right-hand side.  He completely understood that he needed to make a color with red, green, and blue all zero, and he could explain clearly what he wanted his program to do. He just didn’t understand why his program didn’t work.  I find it amazing that he had such a clear view of what he wanted and how his program should work.

As a group, I asked them to try to figure out what the right “brightness” value should be, in order to make a grayscale function.  Here’s what we started with:

```def grayscale(picture):
for p in getPixels(picture):
r = getRed(p)
b = getBlue(p)
g = getGreen(p)
brightness = ???
color = makeColor(brightness,brightness,brightness)
setColor(p,color)```

The question is, what goes in the place of “???”  Somebody guessed “50″ and the others shot him down.  That would fill the whole image with the same gray value.  They guessed “r” (the red channel value) and we tried that — you get a good grayscale, but too light.  Then we tried “b” (the blue channel), and it generates a good-but-dark grayscale.  One of the students correctly said, “We want the average of the color parts!”  So I replaced the right hand side with (r + g + b)/3, and the students started groaning.  ”You can do that?!?”  Now, I had told them that the right hand side of the equals sign could be any expression, and I had shown them various expressions.  What was clear that they hadn’t made the connection that the right hand side of the “brightness” computation could be an expression involving red, green, and blue.

I had lunch once with Randy Pausch, the year that SIGCSE was in St. Louis.  He told me, “Variables are easy! You should never have to spend more than 10 minutes on them!”  I think he was telling the truth as he saw it — for Carnegie-Mellon University students.  Most students that I see as non-CS major freshmen at Georgia Tech, and these high school students, find variables and expressions to have a lot more facets and complexities than I might have guessed.  These examples are just pieces of the interesting ways in which they think of variables.  If we want to help students to learn to code, we have to spend time to make sure that they get these basic ideas like variables, which to us are “easy,” but aren’t when one is first getting started.