Learning 80’s style programming today

There is an ongoing lament among programmers of a certain age that there are no entry-level programming environments for young kids and teenagers to learn on. Since I am of that age, I understand exactly what they mean, but I don’t agree that there are no choices.

Today, on Hacker News, this four-year old article by David Brin in Salon (Why Johnny Cant Code) made the first page. It’s a good read and an accurate overview of the debate— namely, computers from the 80’s came with BASIC, which was simple enough for anyone to pick up and learn how to program, and now, we don’t have an equivalent. Here’s a passage about the difference:

The “scripting” languages that serve as entry-level tools for today’s aspiring programmers — like Perl and Python — don’t make this experience accessible to students in the same way. BASIC was close enough to the algorithm that you could actually follow the reasoning of the machine as it made choices and followed logical pathways.

Luckily, I keep a Commodore 64 Programmer’s Reference Guide on my work bookshelf for nostalgic reasons. Here’s one of the first BASIC programs they list:

10 PRINT "YOUR NAME":INPUT N$
20 PRINT "HELLO," N$

Here it is in Python:

n = raw_input("YOUR NAME ")
print "HELLO, " + n

The Python version doesn’t have line numbers and doesn’t need you to use dollar signs to designate string values. I can’t imagine that anyone who could learn the first one would have any real problem with the second.

But the author is concerned with coding math problems like statistics.  Something where you can follow the logic. Here’s a BASIC program on page 20:

5 PRINT ""
10 PRINT "MONTHLY INCOME" : INPUT IN
20 PRINT
30 PRINT "EXPENSE CATEGORY 1" : INPUT E1$
40 PRINT "EXPENSE AMOUNT" : INPUT E1
50 PRINT
60 PRINT "EXPENSE CATEGORY 2" : INPUT E2$
70 PRINT "EXPENSE AMOUNT" : INPUT E2
80 PRINT
90 PRINT "EXPENSE CATEGORY 3" : INPUT E3$
100 PRINT "EXPENSE AMOUNT" : INPUT E3
110 PRINT "-----"
120 E=E1+E2+E3
130 EP=E/IN
140 PRINT "MONTHLY INCOME: $"IN
150 PRINT "TOTAL EXPENSES: $"E
160 PRINT "BALANCE EQUALS: $"IN-E
170 PRINT
180 PRINT E1$"="(E1/E)*100"% OF TOTAL EXPENSES" 
190 PRINT E2$"="(E2/E)*100"% OF TOTAL EXPENSES"
200 PRINT E3$"="(E3/E)*100"% OF TOTAL EXPENSES" 
210 PRINT 
220 PRINT "YOUR EXPENSES="EP*100"% OF TOTAL INCOME"
230 FOR X=1 TO 5000:NEXT:PRINT
240 PRINT "REPEAT? (Y/N)":INPUT Y$:IF Y$="Y" THEN 5
250 PRINT "-----":END

This example has looping, conditionals, and math. The reverse heart clears the screen (platform specific), line 230 is a delay, and line 240 uses a conditional goto for a loop.

Here it is in python (I tried to keep it as close as possible, also using a platform specific clear screen which will work on the Mac and Linux):

import os
import time

while True:
    os.system("clear")
    IN=float(raw_input("MONTHLY INCOME"))
    print ""
    E1CAT=raw_input("EXPENSE CATEGORY 1")
    E1=float(raw_input("EXPENSE AMOUNT"))
    print ""
    E2CAT=raw_input("EXPENSE CATEGORY 2")
    E2=float(raw_input("EXPENSE AMOUNT"))
    print ""
    E3CAT=raw_input("EXPENSE CATEGORY 3")
    E3=float(raw_input("EXPENSE AMOUNT"))
    os.system("clear")
    E=E1+E2+E3
    EP=E/IN
    print "MONTHLY INCOME: $",IN
    print "TOTAL EXPENSES: $",E
    print "BALANCE EQUALS: $",IN-E
    print ""
    print E1CAT,"=",(E1/E)*100,"% OF TOTAL EXPENSES"     
    print E2CAT,"=",(E2/E)*100,"% OF TOTAL EXPENSES"
    print E3CAT,"=",(E3/E)*100,"% OF TOTAL EXPENSES"     
    print ""     
    print "YOUR EXPENSES=",EP*100,"% OF YOUR INCOME"
    time.sleep(5)
    print ""
    Y=raw_input("REPEAT? (Y OR N)")
    if Y=="N": break
os.system("clear")

So, we have to introduce the concept of import and string to float conversion needs to be explicit, but is this much more difficult? I can tell you that flipping through the C64 programmer’s reference, it doesn’t try to coddle you (it wasn’t written for kids).

The first real program is:

10 OPEN 2,8,6,"0:STOCK FOLIO,S,W"
20 OPEN 1,1,2,"CHECKBOOK"
30 OPEN 3,4

This is under a heading, EXAMPLE OF ACTUAL STATEMENTS in the introduction, which is on the third page of text after the table of contents. To be fair, the syntax of OPEN is briefly discussed, but is this really the best first program?

The one real difference is that a C64 boots into BASIC and you can start typing a program as soon as it’s up. On a Mac, you have to understand how to make text files, open a Terminal, and run python.  After that hurdle, it’s very similar. On Windows, you need to install python.

I think a lot of the nostalgia of what it was like to program these old machines just doesn’t match what it was really like.  The included documentation wasn’t necessarily kid friendly, but there were other sources of information (I had a ton of Compute! magazines and other books).

If you are a beginner, please check out Learn Python the Hard Way. It doesn’t assume that you know anything—it covers getting python installed (not necessary on a Mac) and how to use a text editor. I think it closely matches the kind of experience I and other older programmers remember having in BASIC.