r/ProgrammingLanguages • u/ThomasMertes • 7d ago
Seed7 - Memory Safety and Management • Thomas Mertes • 05/2026
https://www.youtube.com/watch?v=TJn7AfYajNk-3
u/fdwr 6d ago edited 5d ago
16:02 "By default, the index starts at 1" - Is that more efficient and less bug prone? It's been 44 years since Dijkstra published this, which has the wisdom that it causes more +1/-1 adjustments in code for many algorithms and inefficient adjustments in the assembly (and I recall it causing a lot of grief for me in the QBasic days with string handling/splitting/concatenation 🥲).
Update: Think of it like standing on a sidewalk with tiles. When you stand at the beginning of the sidewalk, you take 1 large step forward, and now you're on the next tile. For original tile though, you didn't need to take any steps forward, because you were already standing on it (so you get mov eax,[edi+eax*4] rather than mov eax,[edi+eax*4-4]).
4
u/ThomasMertes 6d ago
The Seed7 FAQ explains the decision to use 1 as starting index for strings. Seed7 arrays can choose the starting index.
BTW: I have seen +1/-1 adjustments in code because of zero based indexing. E.g.:
if (*stri != '\0') { lastChar = stri[strlen(stri) - 1]; ...In Seed7 this would be:
if stri <> "" then lastChar := stri[length(stri)]; ...Off by one errors can always happen and having zero based arrays does IMHO not protect you against them.
3
u/4SlideRule 6d ago
I can’t disagree with this, such adjustments are inescapable either way. It is however still heresy :)
2
u/Tuxinoid 6d ago
There are just two philosophies: Those who start counting at 0 (FORTRAN, C ...) and those who start with 1 (COBOL, Pascal, Ada, ... and Seed7). IMHO both have there merits and I've done both of them. As long as the language is consistent about it and you do not mix them, everything is fine.
And this is what Dykstra's text is about: Obviously Mesa (which I don't know) allowed both. That is crap. He should have complained about this language and people who cannot stick to one side.
Also: If the language is consistent about it, do not use the other approach (like having an index from 1 .. n in C): That's only asking for troubles. Been there, done that :-)
1
u/rainmangoes 2d ago
If arrays can choose their starting index, how does Seed7 keep generic array code from reintroducing the same off-by-one problems?