November 28, 2013

A New Book and a Thanksgiving Wish

Here is my new book: Pencil Code, a programming primer for kids. It is available on Amazon.

You can see in the thumbnails that it is a slim book that presents more than 100 short example programs, each one illustrated in color. There is very little text. This is a book for inductive learning: each important concept is illustrated by an example that is short enough to invite experimentation and exploration.

Run programs at There you will find an online help system as well as hundreds of other users' projects to explore and copy. Save your own projects on by creating your own subdomain there.

I am publishing the book today because I think it will make a good holiday gift for the daughter or son in your family who is just at the edge of being interested in programming computers. The illustrations are a way to invite a little interest, and the short pieces of code make a good project to sit down and work on together with Mom and Dad or brother or sister. Since there are more than 100 projects, there is a little something for everybody: art, games, puzzles, humor, or simulations.

Of course, you can program in Pencil Code without buying or waiting for the book - the online sandbox is free, open-source, and openly available. Here are a few projects to try:

A square
Drawing a smile
Simple loop
Catalog of polygons
Guess my number
Fractal fern
Fractal trees
Turtle race
Chase game
Orbit (click to move the sun)
Bizarro tic-tac-toe (try to lose)

Programming as an Artistic Pursuit

How did you learn your profession?

When I was growing up, my father brought home an Atari 800 and subscribed our family to COMPUTE! magazine. Like several other computer hobbyist periodicals of the era, every issue of the magazine was chock-full of source code for games, algorithms, and utility software.

The printed programs were magic. I would type these programs, not understanding much of how they worked, and I would be rewarded with an amazing piece of running software. Soon I recruited my Mom to type with me. She didn't understand much about the code either. However, she brought an essential skill to the table: she was a trained typist, and so she could help me enter pages of long mysterious code at more than 30 words per minute!

After days of typing and a lot of painstaking typo-checking, a little bit of computer programming wisdom would leak into our heads. Gems such as how the letter "O" works differently from the number "0" even though they look quite similar, or that the "REM" statement (a comment) doesn't actually do anything.

After typing many games that I didn't comprehend, the first program I actually understood was a 10-line prime number sieve. That kernel of knowledge let me build and modify many mathematical algorithms and graphing programs. Then I went back to steal techniques from the magazines to make my own games. Growing up in the era of printed source code was a formative experience. Freelance code published in a magazine made it obvious that programming was a creative, personal endeavor.

For me, the computer was a blank sheet of paper, and writing programs was an artistic process.

But the year I graduated from high school, the world also graduated from printed source code. In May of 1988, COMPUTE! announced that they would no longer print source code in their magazine. Their justification: "As computers and software have become more powerful... we also realize that you're less inclined to type those programs." So by the summer of 1988, the code was gone, and it was replaced by "a complete buyer's guide in each issue to help you find, and then buy, the right software for your computer."

The world had changed. Before that moment, programs were manifestations of personal creativity, distilled cleverness in the same way that poems or symphonies are specialized creative forms. After 1988, programs became industrial products, produced by highly trained professionals working in teams cordoned behind secure gates, and distributed to the public as sealed, shrink-wrapped products.

A Return to 1988

Today there are two trends that make it important to return to the 1988 ethic of personal programming.

First, the economy has been profoundly transformed by the impact of software. There are no corners of commerce - from farming to medicine to manufacturing to retail to trade to finance to war - that have not been fundamentally restructured around the analytical and organizational power of automation. Software infuses everything. While in 1990 we imagined that it was important for the "Knowledge Worker" to be able to be creative with software, in 2013, it is becoming clear that almost all workers must spend some of their time being "Knowledge Workers."

So we cannot teach this generation of children to be afraid of writing programs. They must understand that code is an approachable tool - that it can be used, like a pencil, to do both utterly simple things as well as blindingly complicated things. Tomorrow's adults must have an intuition for how software is created, how it can work well, how it fails, and what role it should play. And they must know that, ultimately, they are capable of creating software. Whether they write a spreadsheet macro to fact-check a statistic, or whether they create an elaborate storefront app to automate their business, tomorrow's workers must be literate in code just as 20th century Americans learned English literacy. Computer code is becoming an essential tool for understanding, cooperation, and commerce.

The Rise of Pseudocode

The second trend is that computers have become faster than they need to be, and that is making them easier to program. In the old COMPUTE! magazines, the experts of the day proudly announced a highly tweaked assembly-language sorting program that was "Capable of sorting 1000 items in 2.1 minutes." (That is a millisecond operation for a mobile phone today.) With slow computers, programs needed to be absolutely optimized for the computer, even if that meant the code was incomprehensible to humans.

Today's computers are so fast that we must make the opposite choice. Most computers spend most of their CPU clock cycles idle, waiting for the user to decide what they want to click next. So when optimizing a system, the right design is to spend as much computer effort as possible to simplify and speed things up for the person. In particular that means that programming languages must be designed to be easy for people to read and write, even at the cost of making programs more difficult for computers to run.

Modern scripting languages such as Python, Ruby, Javascript, and CoffeeScript are all converging on a very similar idiom which in the 1980's we would have called "Pseudocode". These languages look like the chicken scratch that a person would naturally write if using a pencil to describe an algorithm to another person. These languages are readable because they delegate many of the details to the computer. To run a program written in a modern scripting language, the computer must deal with details such as type checking, memory allocation, compilation, and optimization. The programmer is free from these minutiae, and can focus on the underlying concepts.

A Holiday Activity

My hope, in working on Pencil Code, is to do a little bit to help bring these two trends together. Children should learn how to write programs. It is good for the world, and it is good for their personal education. But they should learn how to do it with authentic tools - the same ones used by professionals. Pencil Code helps you program in CoffeeScript. Modern languages like CoffeeScript make it easy to program, and they empower the programmer to do interesting things in the real world. And they let you see through straight though to the real concepts without getting hung up in the boilerplate details.

My wish is that, during the holidays, you will find a moment to play with Pencil Code together with somebody, and open their eyes to the world of coding as a personal and creative endeavor.

Happy Thanksgiving.

Upvote on Reddit.

Posted by David at November 28, 2013 01:09 AM


Hi David, excellent initiative. I'd love to buy your book, but I'd prefer to have a digital version if possible. Any plans to provide an e-book version?

Posted by: Andrea Glorioso at November 28, 2013 08:19 AM

Hi Andrea,

Since there are so many graphics in the book, the automatically-generated digital version looks awful on a Kindle. It will take some effort to make it work in ebook form, and I probably will not do that this year.

For now, a good alternative is just to use the online help area on itself, for example - The online help is not as compact or as neatly presented as the book, but you can enjoy a similar hands-on experience with kids without paper.

Posted by: David at November 28, 2013 08:43 AM

David -

This is fantastic. I'm definitely buying this for my kids as well as for myself. :) Your blog entry brought back so many memories. Of my very own Atari 800 and my subscription to Compute! and spending my weekends typing in all that "meaningless" code (and recruiting my father to help.) Think our dads got two-for-one deals for the computers at Polaroid? :) I can't wait to give it a whirl.


Posted by: Rick Suvalle at November 28, 2013 10:33 AM

Logo through its life has inspired millions. It "grew up" with NetLogo and others but the joy was still there, although a bit less fun traded off for more functionality.

I'll show it to my grandkids this Christmas. Sent for the book, can't wait to see how it can be used by them.

-- Owen

Posted by: Owen Densmore at November 28, 2013 12:47 PM
Post a comment

Remember personal info?