[Coco] [Color Computer] Question about BASIC coding guidelines
James Diffendaffer
jdiffendaffer at yahoo.com
Wed Oct 29 23:10:58 EDT 2008
As for searching through line numbers, Darren is right. If the line
number is lower than the current one the interpreter starts at the
beginning. If the line number is greater than the current one it
starts searching at the next line. (Just so you know, there are some
BASICs out there that include the memory address of the lines being
called so no search occurs. Not on the CoCo though.)
There is one other important detail Darren left out. Variables are
searched from start to end of the variable storage area so you want to
declare most used or time critical variables first. Faster BASIC and
Other Mysteries or some similar book detailed this.
Also, if you can keep a loop on a single line it's faster than spread
over multiple lines. Actually, if you can reduce the number of lines
used by placing more on your lines the less searching has to take
place and the faster it takes place since code is stored in sort of a
linked list. Less lines to search, the lest nodes in the list.
----------------------------------------
On 10/29/08, John wrote:
> Hello all,
>
> I seem to remember BASIC "coding guidelines" said to initialize and
declare
> all variables at the beginning of a program. In addition to making
the code
> somewhat more readable, I seem to remember some minor performance
gains from
> this as well (especially if you declared the most often used variables
> first).
For performance reasons, you should put all initialization code
towards the end of the program in a subroutine and then use a GOSUB to
call it from beginning of your program. The reasoning for this is that
every GOTO statement which branches back to an earlier line number
causes the interpreter to start searching for that line number from
the very beginning. Therefore, the fewer number of one-time-executed
lines at the beginning of the program, the better.
I seriously doubt there are very many programs that will actually
benefit from this kind of optimization.
Darren
More information about the Coco
mailing list