[Coco] What are the rules for naming basic09 variables ?
James Jones
jejones3141 at gmail.com
Sat Jul 27 22:58:16 EDT 2019
The relevant code starts, I believe, at L2430 in basic09_6809.listing. It
accepts a letter followed by some number of alphanumerics or underscores,
optionally with a $ at the end as the string sigil. The loop doesn't itself
bound the length of the variable name, though there's also the matter of
the size of the buffer used to read lines of source code, which would also
bound the maximum variable name length. Further down, though, is
L2459 stb <NAMELEN Save size of variable name
so that a variable name length greater than 255 won't fit in the B register
and the wrong value will be stored in <NAMELEN.
The other thing that may bound the length of a variable name is: what does
the symbol table look like? The first time you see a variable or parameter
mentioned, you have to save its name; the lexical scanner code is looking
through a buffer that I suspect only exists while you're loading or editing
a source file. Depending on how the symbol table is set up, it might have a
fixed limit on variable name length. (I haven't gone looking for the symbol
table yet.)
That said--all that really matters is:
- The maximum length, if it exists, is considerably greater than two, so
in BASIC09 you can have intelligible variable names without coming anywhere
close to the maximum length, if it exists..
- Variable names don't appear in I-code as such, so executing BASIC09
code doesn't involve looking up variable names, and as others have pointed
out, they don't take up space in packed I-code modules.
- You'll notice that a variable or parameter name will always show up in
a listing with the case you used the first time BASIC09 saw it. This, I
believe, implies that BASIC09 only keeps one copy of each variable or
parameter name (the one in the symbol table) around, so even in BASIC09,
the space overhead of variable names is minimized. Also, IMHO, it tilts the
balance towards using camelCase rather than snake_case. Type names the way
you want them the first time, and thereafter you needn't hit the shift key.
BASIC09 will do the work for you, and you don't have underscores taking up
room.
More information about the Coco
mailing list