The other thing that came to mind to me was that you have now defined a maximum string length, unless you then had a meta-length number (describing the "length" of the length). And how long should that number be?
I could see where Ken & Co just looked up and figured null-termination was a more elegent answer.
> The other thing that came to mind to me was that you have now defined a maximum string length, unless you then had a meta-length number (describing the "length" of the length). And how long should that number be?
No it's not. In the first line, it's in [0], in the second line, it's in [1], in the third line, it's in [2]. You have to scan through to find where the '0' appears
True, but it's O(log N) rather than O(N) to determine length.
BTW I'm not sure if it was clear or not but those are bits in my diagram, not bytes/characters. The "x"s are the bits of the length field, not the characters of the string.
But you could just as easily set aside the first 4 bytes of a string to be the length and then it would be O(1).
But does that really matter when you're doing operations on the string that iterate over the whole string anyway? Since iterating the whole string is O(n) anyway, you're not really gaining anything.
I could see where Ken & Co just looked up and figured null-termination was a more elegent answer.