[Coco] Question about BASIC coding guidelines
Arthur Flexser
flexser at fiu.edu
Thu Oct 30 02:57:00 EDT 2008
The claim about performance gains is certainly true, though so small I doubt
you'd notice it in most cases. I wouldn't bother declaring scalar variables
unless they are used really, really often. (Might be worth it for FOR/NEXT loop
variables, if the loop is executed a lot and if BASIC's FOR/NEXT processing
doesn't directly store the variable's address with the other loop parameters
when the loop is entered, which I'm not sure of.) But putting the most
frequently used arrays first in the DIM statement would be good practice.
Since RS BASIC doesn't distinguish between integer and floating-point variables,
I see no particular gain in readability from declaring scalars, nor any method
of doing so other than initializing them to some value, which itself chews up a
bit of computing time. (Conceivably, it is legal to put a scalar in a DIM
statement, but doing so also requires some extra computing time.) Under RS
BASIC all variables are initialized to zero anyway on their initial use or when
a CLEAR statement is executed.
Art
On Wed, 29 Oct 2008, 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).
>
> Anyway, does anyone have any written documentation from any source that
> recommends putting the variables first? I think I may have an old Commodore
> book buried somewhere, but was hoping someone here could point me to a
> source more quickly.
>
> Thanks,
> John Guin
>
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco
>
More information about the Coco
mailing list