Thursday, September 8, 2016

CS222: Teaching students to talk to the client

The theme for the second week of CS222 was Test-Driven Development, particularly the process of determining what test cases should go onto a Beck-style to-do list. I chose the context of a simple text analyzer—a tool with a simple JavaFX UI that takes input text and does some computation over it. The first example I walked through was word counting, just breaking up a string based on whitespace.

The second example I chose was average word length: given a string of words, what is their average length? I explained this to the students and, as an in-class exercise, they broke into ad hoc groups and started coming up with test cases. I gave them fifteen minutes or so, and then we shared our lists. Many of the groups realized that, in order to do average word length, we needed to be able to compute word length, although none of them explicitly extracted this as a separate problem. As they started sharing their test cases, they realized there were ambiguities: some groups were counting apostrophes and dashes as part of the word length, and some were not.

This was a great hook for me to intervene and talk about the dangers of assumptions. Rather than make something up that they wanted, they need to work with the client—or, in this case, the professor as client-surrogate. We also talked about how working on one task may reveal another dependency, and that we can make a separate TDD task list for that. We had some time left, so I told them to shift gears: come up with the list of test cases one could use to write a word length function.

They started, and I wandered the room, giving them about five minutes to complete the task. Then, I stopped them, and informed them that they had all failed. The students looked up at me with a combination of confusion, terror, curiosity, and amusement. "Why," I asked, "did you all just fail?"

With a smile on her face indicating she knew exactly what had happened, a student said, "We just made stuff up. We did not ask the client how word length should be defined."

"Exactly."

It was one of those moments where you can feel the learning in the air.

I wrote down a shorter version of this story in my notes. It was a happy accident this time, but I think it's something I'd like to try to do again.

No comments:

Post a Comment