Teaching BASIC in the 21st century
If you bought a home computer in the 1980s, chances are you learnt a little bit of BASIC programming. The command line interface meant that the difference between starting to play a game and writing a short program was not as big as today, and most of the Commodore 64 User’s Manual was dedicated to explaining how to program your own game or program in BASIC. So for the last few years, our first year Computing Technology: History, Theory and Practice students have had a two hour workshop where they learn to program in BASIC. Here are my notes from the first time I taught this workshop, and the post you’re reading right now gives you some updated ideas.
This is a great class to teach. It’s a simple introduction to a programming language that is of no practical value today, but that was immensely important to a generation of early home computers. The historical value is clear: we use Commodore 64 emulators so get a feel for what computers were really like in the 1980s. It teaches some simple concepts that are important in other programming languages: what is a variable? How do computers follow instructions? Why are programming languages different from each other? And it lets today’s students actually experience working with a command line interface, where you can’t use the mouse and the computer doesn’t register what you typed unless you press enter. Also, it’s very easy to start programming, so there’s instant gratification.
And you can use Nick Montfort, Patsy Baudoin, John Bell, Ian Bogost, Jeremy Douglass, Mark C. Marino, Michael Mateas, Casey Reas, Mark Sample, and Noah Vawter’s wonderful book 10 PRINT CHR$(205.5+RND(1)); : GOTO 10 (MIT Press 2012) which is also available open access as a free PDF. I assigned the first section of the book, which goes through that one line program step by step in a very enlightening manner. You could certainly ask students to read other sections of the book as well.
I’ve got worksheets all worked out so it’s a prepackaged two hour session. Feel free to borrow, steal or adapt. Here is the worksheet I give students as a PDF, and here it is in Word format, in case you want to edit it.
Start the class off by talking a bit about early home computing, and show students this 1983 ad for the Commodore 64 to show them how programming was marketed as a really attractive aspect of home computers.
Once students have got their emulators fired up, explain that the C64 keyboard layout is more or less like a modern US keyboard, but when you press shift you get fancy symbols, so the characters shown on the screen won’t always match what your keyboard says. You can refer to these keyboard layout diagrams.
Some students take quite a while to figure out the command line interface. The computer (well, emulator) won’t process what you type until you press enter at the end of a line. Using the arrow keys to go up and fix a typo won’t work unless you actually press enter for each line you changed. This is not a graphical interface.
Then I hand out worksheets and let students work their way through them. I walk around and help students who are having trouble with the command line interface.
- Let’s start. Type
PRINT “HELLO WORLD”and press return.
- What’s the difference between
PRINT 2 + 2and
PRINT "2 + 2"?
- Make a program by using line numbers. We use 10, 20, 30 rather than 1, 2, 3 so that it’s easy to add new lines in between if needed.
10 PRINT “HELLO WORLD”Type
RUNto run your program. Type
LISTto see the program code. Try adding a line:
15 PRINT “IT’S A LOVELY DAY"Remember this is a command line interface. You can edit lines in the program by using arrow keys to get to the line and typing over the existing words. Then press RETURN or the computer won’t pay any attention to your changes. Another way to edit is to wait for the computer to say “READY” and give you a cursor. The type the line with the error all over again, and press RETURN. Now type
LISTand the computer will show you the whole program, with your corrected line.
- To start a new program (and get rid of the old one!) type NEW.
- Now try a GOTO loop:
10 PRINT “HELLO WORLD”Press ESC to escape the endless loop. This maps to the RUN/STOP key on the original Commodore 64.
20 GOTO 10
REMlets you add comments to your code. Add some.
30 REM THIS IS A NOTE TO MYSELF THAT THE COMPUTER WILL IGNORE.
- We need variables:
10 PRINT "TELL ME A NUMBER"Now type
20 INPUT X
30 PRINT "YOU LIKE THE NUMBER " X "?"
RUN. The computer will show
"TELL ME A NUMBER"on the screen and then a ? and a blinking cursor. That means it wants you to type something in. Now the variable X is set to the number you typed. When your program finishes running, you can try typing “PRINT X” (without line numbers, just as a command) and the computer will show you the number you typed in. It’s in memory now, not just part of the program.
- Now try a text variable (a string). If you want a variable to contain text and not just numbers, you need to put a $ at the end of it.
40 PRINT "WHAT IS YOUR NAME?"
50 INPUT NAME$
60 PRINT "HELLO " NAME$
Play around and see what you can do with this. After a bit of messing around, we’ll do a show and tell.
- Let’s try an IF-THEN loop:
10 PRINT "WHAT IS YOUR NAME?"You can use other operators than the equal sign, like lesser than < and greater than >. <> (is lesser than or greater than) means NOT EQUAL TO. So:
20 INPUT NAME$
30 IF NAME$ = "ENOUGH" THEN GOTO 50
40 GOTO 20
IF NAME$ <> "CORDELIA" THEN PRINT "I REALLY PREFER THE NAME CORDELIA"
Play around a bit more. If you get stuck in an endless loop, you may have to reset your emulator – use the file menu at the top to find the reset options.
- OK, now we’re going to look at an example. Type this program in and see what happens:
10 PRINT CHR$(205.5+RND(1)); : GOTO 10How does this work? Hints: have a look at (or Google) the RND command and the Commodore 64 character set. Now, what can you make, using what we’ve learnt?
OK, that’s all we really have time for in a 90 minute class session. If you come up with improvements or other ideas, I would love to hear about them – please post them in the comments!