Hacker News new | ask | show | jobs
by probably_wrong 735 days ago
> By 1973, it had become “by far and away the single most popular computer game.”

On Lunar Lander and bugs: my first programming book had a version of this game in Basic that I never got to run correctly. 25 years later I came back to it and I was surprised at the ridiculous amount of bugs it had and the convoluted logic ("440 IF <condition> GOTO 450").

I eventually rewrote it as an adult [1] but young me stood no chance. And to this day I wonder what happened inside that forgotten Spanish editorial that turned (almost) working code into whatever made it to the final version.

[1] https://7c0h.com/blog/new/moon_landing_in_basic.html

3 comments

Oy vey, "no chance" is putting it lightly.

A lot of this BASIC code had roots in the 1960's-70's. Back then, editors ruled the roost of print magazines where this code often showed up within, and in books of collections of code they especially ruled with an iron fist. There was little notion that source code had to be dropped in verbatim with absolutely zero changes, so editors would make "judicious" changes in the source code. They thought they were "helping" with "obvious" typographical and editorial decisions.

This lesson was slowly, painfully learned until material improvements across the industry started to take hold starting in the 1980's and realization that source code shouldn't be touched in print really began to permeate the print industry. Though sometimes I wonder if this dynamic spurred the rise of BBS' and helped loosen the stranglehold print media had upon source code distribution, and what an alternative timeline might have looked like if the ones in power in print media were more open to "outsiders" having absolute control over some portion of "their" content.

I learned all the above decades later after I first started playing around with coding as a child, from talking with a much older friend who rose up from within the print media world and saw what happened. When I was a child, with zero adult guidance, and only a handful of books from the school and community library about programming, it was a wonder I stuck with coding at all with the countless programs I typed in by hand from print media that were similarly riddled with errors, so your reminiscing brought back powerful memories.

> They thought they were "helping" with "obvious" typographical and editorial decisions

Sounds completely baffling. How does that thought process even work? What did they think the code meant? What changes did they make, anyway? Did they learn to not touch math equations before?

> How does that thought process even work?

As it was explained to me, it was territory marking/office politics. Editors back then were very powerful when it came to decisions on content. They did not take kindly to anyone explaining/telling them they had no control over any portion of the content.

> What did they think the code meant?

This gets interesting. They were told it was for the computers, but upon seeing high level language artifacts that looked vaguely like English words, they grabbed their red marking pens and leapt into action, absolutely certain they were in the right as they had always been in the past. This was at the very beginning. Later, it got more nuanced.

> What changes did they make, anyway?

Early incidents had stories of galleys using non-proportional font forced to change to proportional font simply due to aesthetics. Red pens changing the contents of PRINT statements (because it said "print", and that was their domain, right?). Even later with more lessons learned and nuances started to creep in, this was way before programmer fonts made the scene, and the typical goofs one would expect from manual transcription were rampant. The pipelines did not exist yet back then for a long time to take raw source code and dump them into the non-digital typesetting systems at the time, so it was all laboriously transcribed from printouts by non-technical staff.

> Did they learn to not touch math equations before?

Very little cross-pollination of editors experienced with math-heavy technical writing, and those overseeing print products popularizing BASIC programming. BYTE magazine was revolutionary at the time for realizing this, and even they had some gaffs from time to time.

That was an enjoyable read. I, too, when I was a child sometimes thought the same thing about my C64 “magically” being able to load some game-related images with just a few lines of code that are… just somewhere inside it? A super bizarre thought, but as a child you’re still prone to a lot of magical thinking.

> and the convoluted logic "440 IF <condition> GOTO 450“

To expand a little bit on that, while some instances in the code of your book could indeed use some cleanup (line 440 is especially egregious), the code in the book was likely written for the common BASICs of home computers of the time, which only operated on line numbers and had very limited branching statements?

The BASIC you use seems to be “structured”, which was extremely unusual for home computers of the time. I just recently saw that a C64 magazine from 1984 spent at least 3 issues of the magazine on a lengthy article series that introduced the readers to the wonders of structured programming!

The severe restrictions of the IF statement made assembly-language style conditional branches (using GOTO) extremely common and necessary.

You definitely could not nest IFs (as done in your code), so if you wanted to combine IFs together, you had to jump over the ones not taken. Commodore/C64’s BASIC (effectively Microsoft BASIC) did not even have ELSE, so usually ELSE had to be implemented with a negated condition and jumping over what would be the “ELSE” branch.

C64 BASIC did however have the interesting quirk that any other statement on the same line would belong to the THEN, e.g.

   10 IF A=1 THEN PRINT “FOO” : PRINT “BAR”
Would print FOO BAR if A=1, and nothing otherwise. This of course worked only so far as you could fit statements on a (limited) single BASIC line. Other BASIC dialects would consider the PRINT “BAR” to not belong to the ELSE anymore, which is syntactically cleaner, but could be less convenient depending on what else the dialect offered.

A lot of the convenience and rigor we take as granted today wasn’t there. C64 BASIC seemed especially “dirty” to me, having lots of bizarre quirks that are more the result of its implementation. (Another random instance: Every function had to have an argument, whether it was required or not, so you had to write something like “?FRE(123)” to print the amount of free memory, where the 123 did not matter at all.)

Probably copy/paste errors (in editorial) mixed with deadlines mixed with no QA.