This first lab includes four projects in its six pages. Pages 2 and 3 are a single project, and page 6 brings together ideas about debugging some of which were introduced earlier in the course; it isn't a project at all. What the four projects have in common is that they introduce different ways of thinking about more complex programming problems than students have seen so far:
The later programming labs in this unit focus on lists for data abstraction.
move
and turn
.
if (size > 9)
block and the implicit "base case" is: if size ≤ 9
then stop drawing.move
blocks.draw row A
block than the draw row B
block due to its two smaller bricks. Getting the two rows to span the same length will require some trial and error.draw brick wall
block definition must identify whether an even or an odd numbered row is being built. One way to do that is to call odd?
on the row number for each row. Another way is to make height/2 repetitions of a draw row A
and a draw row B
, then see if the total height is even or odd to decide whether or not to draw a final draw row A
.draw brick
they might want.Too much abstraction? It's possible to go overboard on abstraction and build so many blocks that your program is just as cluttered as it would be without the special blocks.
But it can also be useful to make a special block even when its definition is just one built-in block. For example, to draw the mortar (the cement between bricks, shown as white space), you can just use move (4) steps
, but it might make sense to define a draw mortar
block.
Why? You might later decide that 4 steps is the wrong thickness for mortar, and you'd rather have 5. Or you might want the mortar to be cement-colored, slightly gray. With many move
blocks scattered through your program, you would have to find and change each one, and keep putting in set pen color
blocks. With a draw mortar
block, you can just change its definition and all the mortar in your picture will be changed.