Teaching Programing Skills to Children with Logo

As a parent of three young boys, I often think about what it's going to take to be competitive in the job market of the future. Obviously, they'll need solid reading, writing, math and science skills, with history, literature and art thrown in to make them well-rounded. Being a computer nerd myself, I recognize the value of even basic computer skills.

Workers of the future will need to be able to use a word processor and spreadsheet, and they'll need to be able to send and receive e-mail. Those skills are so basic, they probably just barely will qualify people for a decent job. What will separate job seekers from the competition will be basic programming ability and the thinking processes that go with it. Although I don't advocate trying to teach your five-year old to program in C or Java, I do think you should start early. The Logo programming language is a wonderful way to introduce young kids to the art, and science, of programming.

For those of you who aren't familiar with Logo, essentially, it's about giving programming instructions to a frog, who then executes those instructions. The frog understands basic commands, such as “forward”, “backward”, “turnleft” and so on. This wonderfully intelligent and obedient frog also happens to be carrying a magic marker that he can use to trace out his path as he moves about on the computer screen. By sending the appropriate commands to the frog, you can cause him to trace out geometric shapes. For the parent or teacher, it's nice to know that the Logo programming language is easy to learn. I learned it in about 30 minutes, and I was fighting the flu. After all, it's simple enough for a frog, right?

Most of the Logo programming commands are pretty self-explanatory. The “forward” command takes one parameter, the number of pixels to move forward. The “turnleft” command also takes one parameter, the number of degrees to turn. The “go” command takes two parameters, X and Y, that describe a location on the screen where the frog should go. The “pendown” command tells the frog to put his pen against the ground so that it traces his path as he moves. Conversely, the “penup” command causes him to lift his pen so that he can move without leaving a trace. Amazingly, this pen also can change its width and color with the “penwidth” and “pencolor” commands.

The “clear” command erases all of the traces left by the frog, but it leaves the frog wherever he is. The “reset” command clears the screen and puts the frog back at the center. Most Logo programs will start with a “reset” command, unless part of the program entails being able to start from an unknown state.

This frog also understands math. He can add, subtract, multiply and divide. And, he apparently is well educated, as he knows the number pi and trigonometrical functions like sin, cos, tan, arcsin, arccos, arctan and the functions sqrt and exp. Of course, he also understands the concept of a variable to which your kid's program can assign values for later use.

Logo also supports program loops and branches. The if statement takes a (possibly compound) boolean expression and executes a bracketed block of code if the expression evaluates to true or an optional alternative block otherwise. Essentially, it looks like:

 
if <expression>
{ block } else { block }

There also is a while loop, a repeat loop (which simply loops a given number of times) and a for loop (which looks a lot like the for loop in BASIC).

For this article, I'm using KTurtle, which comes with the KDE environment. KTurtle essentially is an IDE that has a programming window, an execution window, an errors window and a debugger. You even can control the speed at which the frog executes your instructions. I'm sure there are other implementations available besides KTurtle. Let's take a look at a simple example so you can get a feel for what the language looks like.

reset
forward 30
turnleft 90
forward 30
turnleft 90
forward 30
turnleft 90
forward 30

This little program almost doesn't warrant an explanation. It simply clears the screen and draws a box with sides 30 pixels long.

Let's do a more complex example that shows of some of the frog's abilities.

$sides = 100
reset
$dotted = 1
repeat $sides {
	if ($dotted == 1) {
		pendown
		$red = random 0,255
		$blue = random 0,255
		$green = random 0,255
		pencolor $red,$blue,$green
		$dotted = 0
	} else {
		penup
		$dotted = 1
	}
	forward 5
	turnleft 360/$sides
}

This little gem simulates drawing a circle by drawing a 100-sided figure using dotted, multicolored lines. Actually, there's a bug in the program that becomes obvious when you change the number of sides to values less than about 20.

Fixing the bug in the previous program is a nice way to introduce one final feature of the Logo programming language: structured programming. Logo allows you to create your own commands, or subroutines, using the “learn” command. For example:

learn dottedline $n {
	$dotted = 1
	repeat $n {
		if ($dotted == 1) {
			penup
			$dotted = 0
		} else {
			pendown
			$dotted = 1
		}
	forward 2
	}
}

This snippet of code enables our frog to execute a new command called dottedline. Now our program looks like this:

$sides = 20
learn dottedline $n {
	$dotted = 1
	repeat $n {
		if ($dotted == 1) {
			penup
			$dotted = 0
		} else {
			pendown
			$dotted = 1
		}
		forward 2
	}
}


reset

repeat $sides {
	$red = random 0,255
	$blue = random 0,255
	$green = random 0,255
	pencolor $red,$blue,$green

	dottedline 6

	turnleft 360/$sides
}

And, if we run this program, we see a a 20-sided “circle” made with multicolor dotted lines. This program also behaves properly when sides=3, where the previous program did not. There's still the matter of scaling the “circle” as the number of sides gets larger, but that's beyond the scope of this article.

As you can see, Logo is a fairly simple, yet complete, language. The examples I've presented later in this article are probably a bit advanced for most young programmers; however, older programmers should be able to follow and understand this level of program logic. At this point, they should move on to a more advanced language. In the meantime, your younger students can learn to use commands to draw geometric shapes and pictures.

As a parent or teacher, I'd recommend starting by having students give the frog basic commands so they become familiar with the results. Then, as the students become more sophisticated, provide them with increasingly more complex geometric shapes and have them write a program to mimic that shape. If this is as far as you go, think about what you will have accomplished. Your students will have acquired mouse/keyboard skills, geometric/spacial thinking ability and rudimentary programming experience, and they probably will have a few giggles in the process. As long as you guide them along to keep them from getting “stuck” and frustrated, they'll do just fine.

As an introduction to structured programming, I'd present them with a working program like this:

learn box $count{
	repeat $count {
		turnleft 360/$count
		forward 20*5/$count
	}
}

reset

repeat 20 {
	box 5 
	turnleft random 1,360
	penup
	forward 50
	pendown
}

Let the students identify all the “tunables” in this program, change them one by one and observe the results.

As you can see, Logo is an easy language for an instructor to pick up, and yet, it's still very approachable for very young students. There's probably not much demand for Logo programmers in the job market, and I'm not trying to imply that my sons will grow up to be programmers, but basic computer and programming skills will give them many choices that they otherwise might not have, and the Logo programming language is a good first stepping stone.

Load Disqus comments