If you’ve never programmed a computer, you should. There’s nothing like it in the whole world. When you program a computer, it does exactly what you tell it to do. It’s like designing a machine — any machine, like a car, like a faucet, like a gas-hinge for a door — using math and instructions. It’s awesome in the truest sense: it can fill you with awe.
A computer is the most complicated machine you’ll ever use. It’s made of billions of micro-miniaturized transistors that can be configured to run any program you can imagine. But when you sit down at the keyboard and write a line of code, those transistors do what you tell them to.
Most of us will never build a car. Pretty much none of us will ever create an aviation system. Design a building. Lay out a city.
Those are complicated machines, those things, and they’re off-limits to the likes of you and me. But a computer is like, ten times more complicated, and it will dance to any tune you play. You can learn to write simple code in an afternoon. Start with a language like Python, which was written to give non-programmers an easier way to make the machine dance to their tune. Even if you only write code for one day, one afternoon, you have to do it. Computers can control you or they can lighten your work — if you want to be in charge of your machines, you have to learn to write code.
–Cory Doctorow, Little Brother
Partly inspired by that paragraph, this summer’s craze for me is teaching my friends to program; so far five different people have let me start them off on the basics. I don’t necessarily hope to make professional programmers or dedicated hobbyists out of them all; I have a couple of more modest goals:
I started when a friend who is doing a creative writing degree said something like “But don’t you have to learn a lot of theory before you can start to program?” I grabbed the laptop, opened an editor window and typed
print "Hello world"
“That is a complete computer program” I said. “Can you guess what it does?”
From there it was easy to move on to a succession of slightly more complicated programs, demonstrating each of the major building blocks of programming languages in turn. I’m not sure she’s going to ask for a second lesson, but I think she left the first with the feeling that what I do for a living, or where the software she uses comes from, is that bit less mysterious.
However, programs that print things on a terminal aren’t necessarily the most fun or engaging things to play with – I tried relying on that for a second, more hands-on lesson with another friend, and I think the fun vs frustration ratio left something to be desired. The usual solution to this is turtle graphics as pioneered in the programming language Logo, but I found it hard to think of any interesting programs to write with the turtle – it seems as though to get a lot out of it, you have to really like geometry, which few of us do.
Much more appealing is the grid-based world of Karel the robot. While the turtle wanders around the barren infinite plane with only its own lines for company, Karel’s world includes impassable walls aligned with the grid lines and objects called “beepers” in the grid squares that the robot can detect, pick up and put down. This makes it natural to write programs that do more than follow a predetermined sequence of steps – programs that actually discover the state of the world they find themselves in and adjust how they act appropriately.
These ideas have been picked up in other tools, most notably the teaching environment Guido van Robot. However, in common with its predecessor, these environments teach their own custom language: once a student is ready for greater things, they must start learning a new programming language. I’m no pro at these things, but I’m inclined to see this as a waste; the syntax of Python is easily simple enough for a beginner to start with right away, and I think it’s a powerful selling point and confidence booster for the student if you can honestly say that the language that they are now learning is used by choice at Google and all over the world by real programmers with real jobs to do.
So this finally led me to my favourite tool so far: RUR-PLE.
RUR-PLE is exactly this synthesis: it provides the maze-like environment of Karel and Guido van Robot, with the syntax of the real Python programming language. RUR-PLE ships with a range of pre-designed mazes for various programming challenges that introduce the key ideas of the Python programming language in a fun way, as well as a complete HTML manual for learning programming.
And it really works – people found it intuitive and rewarding to move the robot, and it was easy to come up with maze-based challenges that illustrated programming concepts. The simple integrated debugger meant that whenever it did something unexpected, it was easy to take it through step by step to see why it was doing what it did, and the robot graphics provided satisfying instant results. I knew I was doing something right when one friend practically ran back to the computer after dinner to finish debugging her maze solving application.
However, there are a few problems with RUR-PLE. The user interface is in many ways unnecessarily complicated and unintuitive. The program provides four “tabs” with four different functions that to me would be better provided as four separate applications, especially since one is a browser window with a lesson plan where most users would prefer to use the browser they normally use. There is no menu bar, so everything has to be done with buttons on the toolbar. This toolbar is written in a non-standard way that is less attractive than platform standard ways of doing these things. The robot is drawn in elevation even though the maze is seen in plan, which makes life harder for users who are already tripping up on telling their left from their right, and the squares of the grid are at right angles to the walls instead of lined up with them, just one of the unnecessary visual complications in the grid; another complication is that the Python editor is a full folding editor, useful for experienced programmers but another potential source of confusion for beginners. Users are instructed to call a “turn_off()” instruction at the end of every program, a rather unPythonic way of doing things that makes the simplest working program twice as long as it needs to be, and which turns out to be a hangover from its Karel-based roots – as is the rather confusing name of “beepers” for the objects that the robot can pick up and put down.
Since it’s in Python, I thought these problems (and others, such as that you can’t change the speed at which the program runs once it’s running) would be easy to fix, but as I started digging into the code I discovered that the structure made fixing these things hard. As I learned later, the author wrote it as part of an exercise in teaching himself Python programming, and it shows: the code is in many places more verbose than it needs to be, and the abstraction that would allow me to restructure the UI while keeping the core functions in place was absent.
So I did what one should never do: I started a complete rewrite, now called “Rurple NG” for “Next Generation”. And I’m pleased to report that so far I’m getting very nice results. There’s still a certain amount of work left to do, as the TODO file in the sources shows. But it works, and it’s good enough to use for teaching purposes now. I encourage you all to download the sources and help me hack on it or help write documentation, or simply try it and give me whatever advice you can on how this can be made better.
I think most people imagine that programming is far beyond their abilities, but I believe learning to program is one of those things that nearly everyone can and should do; it’s directly beneficial even if you only ever write tiny programs to do what your existing tools can’t quite do, but it also has tremendous indirect benefits in understanding not only computers but mathematics and logic, as well as the special discipline of debugging. I hope that I can create an attractive and friendly tool that could bring programming to a new audience, and help open up our mysterious world just a little bit.
You are currently browsing the LShift Ltd. blog archives for August, 2009.