<<< long weekend ...

Home

US Pro Cycling Challenge, redux >>>


one byte mistake

Sunday,  08/28/11  07:46 PM

An article in ACM by Poul-Henning Kemp claims the decision to null-terminate strings is the most expensive one-byte mistake.  Not even.

Null-terminating strings was a great design decision, especially compared to the alternative of preceeding each string by a length.  First, a length "byte" would be just as prone to being corrupted as a null terminator, maybe more so.  Second, who's to say one byte is enough?  255 characters isn't very many, and if you need more than one byte, how many more?  Always two?  Always four?  If it's variable, how do you know?  Big endian or little?  Or both?  Third, how do you handle variable-length strings which grow - do you reallocate the whole string to make the length byte bigger?  The problems go on and on.

As the author notes, C has mostly be replaced by ${lang}, and in ${lang} you have string objects which encapsulate the byte arrays anyway.

The real most expensive one-byte mistake was using backslashes as path delimiters in DOS, which is even mentioned in this article.