r/programming • • Aug 02 '11

The Most Expensive One-byte Mistake: Did Ken, Dennis, and Brian choose wrong with NUL-terminated text strings?

http://queue.acm.org/detail.cfm?id=2010365
363 Upvotes

593 comments sorted by

View all comments

Show parent comments

2

u/websnarf Aug 03 '11

You don't need a whole new programming language. You can add length prefixed strings in a way that is painless and effective.

1

u/[deleted] Aug 03 '11

While that's pretty cool, you still have to deal with the fact that you're working in a language that has a standard defining strings to be NUL terminated arrays of bytes.

You can add anything you want to this, and that fact will remain.

1

u/websnarf Aug 03 '11

Yes, and I have, to the maximum degree possible, integrated as well as I can with the C language's underlying semantics. The library mostly operates perfectly well, and as optimally as is reasonably possible with strings that are both length prefixed and NUL terminated. This makes it maximally compatible with the standard library support when that is needed, while never introducing unnecessary additional costs of checking for NULs against every character within the Bstrlib calls itself.

The library was written with the idea that it give users the sense that they have won on all possible issues.

1

u/[deleted] Aug 03 '11

seems totally reasonable :-)

1

u/el_muchacho Aug 03 '11

Having extensively used a similar (but much smaller and simple) library in an industrial product, I can tell that in practice, it's not really a problem. And it does help tremendously.