[Coco] Question about BASIC coding guidelines

Darren A mechacoco at gmail.com
Wed Oct 29 20:54:27 EDT 2008


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