Strings, encodings, NULs and Bazel

Just yesterday, Twitter user @vkrajacic wrote:

Advice for new C programmers: “Avoid null-terminated strings; they’re outdated, inefficient and impractical.”

Create your own type with basic functions. It’s not that hard, and it goes a long way. One of the benefits of this approach, among others, is slicing without copying.

This suggestion has its merits and I understand where it is coming from: performance. You see: the traditional way to represent strings in C is to use NUL-terminated byte arrays. Yet… this has deemed to be the most expensive one-byte mistake because of the adverse performance implications that this carries. (NUL, not NULL, is the better name for the \0 byte by the way.)

December 3, 2023 · Tags: bazel, blogsystem5, java
Continue reading (about 4 minutes)