47 ms·
BASICs string handling is an underrated treasure of early programming languages. Notably MS-BASIC and relative. What folks take for granted, without really kno
by whartung 3y ago
BASICs string handling is an underrated treasure of early programming languages. Notably MS-BASIC and relative.
What folks take for granted, without really knowing it, is that the MS-BASIC system was a rather early system with built in garbage collection.
Consider:
A$=“Hello “
B$=“world.”
FOR I=1 TO 10
A$=A$+B$
NEXT I
We just take for granted that this will just work, but there’s a bunch of junk created here that eventually needs to be cleaned up.
This is in contrast to the HP style BASIC that used dimensioned strings. This was much simpler and just needed work buffers that were readily reused.
MS had some notoriety about bad performance when things got too tight. But it’s cool to know there was this nice little bit of tech buried in 8K of 6502 or 8080 from the late 70s.
- ustad 3y agoDo you have any references to the “HP style BASIC”?
- whartung 3y agoHere's a quick overview. https://en.wikipedia.org/wiki/HP_Time-Shared_BASIC#String_handling https://en.wikipedia.org/wiki/HP_Time-Shared_BASIC#String_ha... The key detail is that HP BASIC dimensions the individual strings, where MS does not. Since the HP strings have dimensions, they're constrained. Given a typical max length of 255, you can see a string expression being done with a 255 byte work buffer and, when complete, moved into the dimensioned space. So, in the end, there's just a work buffer and the string. With MS, strings are just pointers to places in memory (for examples the static strings in the code). So it's a whole "malloc/free" thing with the strings, but if the work space fills up, you can compact the heap and move the variable string pointers. Different mechanic. Simple garbage collection, but it is garbage collection.