Rhapsody in C, Sonata Basic

2011/03/02 § Leave a comment

I am perhaps bit weird in that the first programming language I learned was not the first programming language I used.

In primary school I used to borrow these “game collections” from the library. They contained a variety of program listings, always BASIC, which I then slavishly fed into BASICA (or later QBASIC). There were always a few variants because each popular computer had a slightly different language; the IBM PC must have been too prescient for these books and thus never listed specifically. Luckily, I figured out early on (probably by trial and error) that the Apple II versions always worked for some reason.

In any case, I’d write these thousand-line programs into a glorified text editor:

A BASIC LISTING

1 PRINT TAB(28);"RUSSIAN ROULETTE"
2 PRINT TAB(15);"CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY"
3 PRINT:PRINT:PRINT
5 PRINT "THIS IS A GAME OF >>>>>>>>>>RUSSIAN ROULETTE."
10 PRINT:PRINT "HERE IS A REVOLVER."
20 PRINT "TYPE '1' TO SPIN CHAMBER AND PULL TRIGGER."
22 PRINT "TYPE '2' TO GIVE UP."
23 PRINT "GO";
25 N=0
30 INPUT I
31 IF I<>2 THEN 35
32 PRINT "     CHICKEN!!!!!"
33 GOTO 72
35 N=N+1
40 IF RND(1)>.833333 THEN 70
45 IF N>10 THEN 80
50 PRINT "- CLICK -"
60 PRINT: GOTO 30
70 PRINT "     BANG!!!!!     YOU'RE DEAD!"
71 "CONDOLENCES WILL BE SENT TO YOUR RELATIVES."
72 PRINT:PRINT:PRINT
75 PRINT "...NEXT VICTIM...":GOTO 20
80 PRINT "YOU WIN!!!!!"
85 PRINT "LET SOMEONE ELSE BLOW HIS BRAINS OUT."
90 GOTO 10
99 END

The above program is an example. Though this is probably not the version I originally used, I am somewhat impressed and disturbed that one of the first games I remember repeatedly enjoying was Russian Roulette. It was probably also one of the few games where I could reverse engineer what the code meant, as it didn’t involve any graphics, and thus lacked the mysterious POKE and PEEK and DIM statements that still perplex me. The keywords were reasonably verbose enough for me to understand their context. This was before the Internet, and for whatever reason my library had no basic programming language manuals, only guides on how to use various programs (and these game-books.)

I suspect many kids actually used these books to type in programs before even understanding what they were writing. Perhaps I’m not all that different.

Anyway, the first language I ever understood as a language was C. Eventually I found a book on C in my father’s secret science fiction stash. It was simply called “C”, or something like it. The author was the founder of a compiler company that’s longsince been dust. I can remember the cover, a large Red C on a dark background, but not much else beyond the sparseness of its typeface.

THE C I KNEW THEN

#include <stdio.h>

first_function(f)
{
   return f + 5;
}

main(argc, argv)
int argc, char** argv;
{
    printf("Hello World!\n");
}

The book never explained the process of compilation, it assumed I’d have the smarts to know that I need to do something to the code I write in order to make it run. I may have at first tried to type the program in BASICA and quickly figured out that hitting F2 (RUN) and wondering why everything failed. Eventually I gave up and just wrote attempts on paper, placing faith in my correctness. It never occurred to me to ask my dad for a C compiler, probably because the book never talked about needing one and I couldn’t abstract my use of BASICA into a need I could demand from him. Even when I did sneak a compiler from my father’s pile of disks, enough years had passed that the syntax I had learnt had since been superseded by the ANSI standard. I learned C long before I got around to being able to use it.

THE C I KNOW NOW

<pre>#include <stdio.h>
</pre>
int first_function(int f)
{
 return f + 5;
}

int main(int argc, char** argv)
{
 printf("Hello World!\n");

 return 0;
}

Given that my programming experiences have mostly been in the context of C++ and given that I haven’t yet read the pinnacle of C reference books, I still wouldn’t consider myself remarkably fluent.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading Rhapsody in C, Sonata Basic at The Lambda Calculus.

meta

%d bloggers like this: