Comment by ZeroConcerns

Comment by ZeroConcerns 2 days ago

3 replies

I'm not exactly sure what's going on with this article and whether it's just the language barrier or something else, but... it doesn't make an awful lot of sense?

'Tricks' like 'not including too many comments' were already well-known from day one of the ZX line (which started around 1980) because, well, you had 1K, 16K or 48K or RAM to work with, so every character counted!

Also, you were painfully aware of the performance of inner/outer loops, because, absolutely, a sub-3 MHz clock speed doesn't leave many other options. Other than to migrate to assembly coding, which was where most serious Sinclair coding took place.

The article is right about one thing, though: the Sinclair BASIC interpreter was a work of minimalist art, as was the hardware. "Sure, let's multiplex the audio-in line with the video sync signal, so we can save a pin on the ULA" is not something that gets a lot of consideration these days...

egypturnash 2 days ago

"You can poke new values into the start-of-program pointer to speed up jumps to the end of the program, and speed up loop execution" is pretty tricky. So's "you can poke new values into another pointer to jump to arbitrary statements within a multi-statement line, and here[1] is a 3d maze program that abuses the heck out of this to become a one-liner".

1: https://spectrumcomputing.co.uk/entry/21001/ZX-Spectrum/1_Li...

amiga386 a day ago

It makes a lot of sense to me.

They key problem is that GO SUB and GO TO are not instantaneous like a CALL or JP instruction would be in Z80. The BASIC interpreter does a linear scan through the entire source code, until it reaches the specified line number. Every time you want to jump or call.

That's why this article is called "Efficient Basic Coding"... all the "tricks" are about moving the most frequently called code to the lowest line numbers, so the interpreter spends as little time scanning the source code destination line numbers as possible.

The second article in the series is on a theme, where variables aren't indexed either, the interpreter scans through each variable in turn until it finds the one with the name referenced in the source code... again you want to define them in order of most frequently accessed...

Zardoz84 2 days ago

> 'Tricks' like 'not including too many comments' were already well-known from day one of the ZX line (which started around 1980) because, well, you had 1K, 16K or 48K or RAM to work with, so every character counted!

But that GO TO/GO SUB target position in the code list matters, because does a linear search (so the no use comments, isn't only about wasting RAM), was new for me. And I toyed with a ZX Spectrum as child.