Chapter 12
[ 311 ]
Hiding complexity
Overall, what we found was that, by hiding some of the complexity inside a runtime
environment, the kids were able to focus on getting their own pieces of the code
to work. This turns out to fit well with what they would have experienced in the
other classes. Most would have started programming in the Scratch environment,
https://scratch.mit.edu/.
Scratch is a visual programming environment for kids where they can plug
together logic elements in a drag and drop editor. It's a visual DSL for kids.
When they arrive in the Groovy class they are used to having a lot of power at their
fingertips. HTML teaches them that syntax is important and that they need to be
careful about what they write, but it also gives them an expectation that they can
produce a rich user interface.
Entry into the Groovy room is supposed to be a graduation from the Scratch and
HTML world and it certainly is. It's the first introduction to proper programming
so to speak. Groovy, as we know it, is a lot simpler than Java and requires less
punctuation but it is still a step beyond either Scratch or HTML. We wanted to
avoid the trap whereby the Groovy class was considered too hard or too boring
because the kids did not get enough feedback for their efforts.
With this in mind, we began to take the approach that we would provide framework
classes as helpers for the kids. The more advanced students would be able to
help build the classes while the others were happy to be able to build programs
using them.
An ongoing theme during term was a project to build a functioning TicTacToe
program. This was a console-based program that started out just taking user input
to allow two players to play each other on the same computer. We then started to
introduce concepts that allowed the kids to write code to automate the game. By the
end, most of the students had understood the concepts and were able to write simple
player strategy classes like the following. These are actual classes developed by
Nathan and Eoghan, two of the CoderDojo Ninjas.
class NathanPlayer extends Bot {
def playRound(grid) {
if (!Grid.isSolved(grid)) {
if (Grid.canWin(grid,this.player))
Grid.playWin grid, this.player
else if (Grid.canBlock(grid, this.player))
Grid.playBlock grid, this.player
else if (Grid.canTakeCenter(grid, this.player))
Grid.playCenter grid, this.player
else if (Grid.canTakeCorner(grid, this.player))