Poul-Henning Kamp: The Most Expensive One-byte Mistake
queue.acm.org
queue.acm.org
There is a huge cultural blindfold that Unix/C have formed indirectly formed on everybody's thinking about computers. Most of us have never used computers outside the Unix sphere of influence.
The point about hardware (in this case instruction set) adapting to Unix/C strings is also a recurring pattern, and makes it hader to climb out of the pit of local optimum /path dependence.
Fun thought experiment to think how things might have turned out if ideas from Burroughs mainframes, Transputer, Lisp machines or Intel i432 type of things had taken off.
But Unix was easy to port because of simplicity, kinda-open-source for universities, etc. even though those properties soon disappeared after it became popular. And we know the rest.
I do agree that zero-terminated strings are the worst idea ever. It's almost impossible to use them in a secure and performant way (at the least it requires a lot of extra thinking). Alternative string libraries such as bstring make string handling in C sane, but unfortunately the default C strings mean a lot of people still use char* and str(l)cpy/str(l)cat/strlen/...
The worst thing is that many are religiously convinced that it is a good idea just because it's the UNIX and C way (TM). It's so deeply ingrained.
The cultural bindfold you refer to is because there has been no comparable revolution in operating systems design since Unix, people tinker (comparatively) at the edges because Unix got so much right. NUL terminated strings is a minor aspect of library design. Yes with hindsight if things had been done differently then things might now be different, but like the QWERTY keyboard once decisions get out in the world they become too difficult to reverse.
Have you ever used a Burroughs mainframe? They did have a rather wonderful architecture but the interactive user experience from CANDE left a lot to be desired.
However, one positive thing about briefly using CANDE was that it made me REALLY appreciate Unix when we eventually moved to using it.
Now, if it had been about NULL pointers, then Tony Hoare has called them his billion $ mistake.
Is there an anti-pattern here?
NULL. Just say no :)
Reading this made me realize very few people fully appreciate how good compilers have become these days.
I'll add some love to the MS C# compiler, despite its shortcomings, just because whoever worked on it absolutely deserves some love.
... look upon my gets(), ye mighty, and despair?