tutorials reflection

Programming with Understanding

Posted on by Abraham

You can’t learn to speak — to say things — without learning to say something. And you can’t learn to program — to talk to a computer — without learning to program something. Learning to program therefore not only provides the opportunity to learn to instruct a computer, but is also an opportunity to learn about everything else in the world.

When learning something new, by coming to understand its fundamental elements or building blocks you’ll not only learn more, and more exciting things, but have a greater amount of expressive power with that knowledge. It is essential, however, that the process of learning those detailed fundamentals takes place with the big picture always in mind, and in sight. Literally as well: appropriate visuals greatly improve the learning process by serving as memory and reasoning aids.

Turtle graphics

Turtle graphics are therefore an excellent introduction to computer programming. For most people — both adults and children — turtle graphics also kicks off the process of re-associating mathematics and logic with beauty, both visual and intellectual. With turtle it is surprisingly easy for even a child to draw interesting graphics with a small amount of code. Being able to imagine yourself as the turtle makes it easier to figure out how to move the turtle to draw something, which is called body-syntonic reasoning. The immediate visual feedback then directly shows you what your code does, and you can see whether that is what you intended it to do or not.

In Turtle geometry we create an environment in which the child’s task is not to learn a set of formal rules but to develop sufficient insight into the way he moves in space to allow the transposition of this self-knowledge into programs that will cause a Turtle to move.

— Mindstorms: Children, Computers, and Powerful Ideas

In other words, when a person understands the essence of their own movement, they can begin to command the turtle to move as they want it to.

Suppose that you’d like to command the turtle to draw something as simple as a circle. How would the turtle have to move to do that? To answer that, imagine yourself as the turtle and think about how you would have to move, literally step-by-step, so as to walk in a circle. Each step would be something like forward a little bit, then turn a little bit, then forward a little again, then turn a little again, etc. all the way back to the start — try it! That then is exactly what the turtle should do, as in the Python program below. To execute the code, install an editor like Thonny, type (or copy) the code into it and select the ‘run’ or ‘play’ button:

import turtle

for steps in range(18) : # let's turn 18 times, doing the following each time:
    turtle.forward(25)   # move forward 25 units
    turtle.left(20)      # turn left 20 degrees (360 / 18)

An animation of a circle being drawn step by step.


Once a person has explored the programming of all sorts of relatively basic drawings, the next step is usually to advance to more involved graphics that make use of more complex logic like conditionals and functions with recursion. But people can then start getting bored. As computers are blazingly fast, however, we don’t need to stick with static drawings, we can bring them to life as animations. In the next post — Animation with Turtle Graphics — we’ll dive into the fundamentals of animation, then use that understanding to create our own animations.