Wednesday, May 31, 2006

Amazing Spaghetti

On Gadgetopia I read that "Someone scanned in all the pages from the classic book BASIC Computer Games". I remember back in elementary school and high school I used to get magazines and books from the library with program listings.

I rarely ever actually typed in the listings, though -- I was too lazy for that. Instead, I'd often try to figure out how the code worked. My favorites were the listings that also had an explanation of how the program worked. Then I'd typically ignore the listing entirely and just try to write a program based on the description. I remember writing a fractal landscape generator in BASIC 7.0 for the Commodore 128 based on an article in Compute! which had a listing for an IBM PC fractal landscape generator.

Anyway, back to BASIC Computer Games: Looking at the scanned cover, I felt like I remembered this book. I remember borrowing it from the public library back in high school and being surprised by the seemingly ancient version of BASIC that it was using. I don't know if it was actually an "ancient version of BASIC", that's just what it seemed like to me at the time. The book was published in 1978, well before the Commodore 64, my first computer, even existed.

There was one program in the book that really intriguied me: a random maze generator called "Amazing". By the time I got my hands on the book my programming language of choice was Turbo Pascal, so I decided to try and port "Amazing". I never actually succeeded because Turbo Pascal is structured, while "Amazing" made copious use of spaghetti like GOTOs.

The first thing I did when I found out about the scan of the book today was to check if this really was the maze generator I remembered. I remembered that the program had lots of "GOTO 1000" statements, and that line 1000 was itself a GOTO statement (making the program worthy of TheDailyWTF, IMHO). Sure enough, if you check the listing of Amazing you can see that spaghetti I was up against.

The funny part is that the program listing is only about 150 lines long, which is actually pretty short. I think I'll take another crack at translating the program, though this time I'll probably use Python rather than Turbo Pascal.

posted Wednesday, May 31, 2006 (1 comments)