3 ms·
> Only because the C FFI is the lingua franca of operating systems. No, because they are genuinely useful. How should you best implement Option<type> for point
by jstimpfle 4y ago
> Only because the C FFI is the lingua franca of operating systems.
No, because they are genuinely useful. How should you best implement Option<type> for pointers? Right, using NULL as a sentinel. And representing sum types explicitly in the type system (instead of ad-hoc using sentinels) would add a huge amount of complexity.
I still like the simplicity of zero-terminated strings. They are self-contained strings that can be passed around as a simple char-pointer. No other format can give you this simplicity. They are still an acceptable default for string literals. And whenever you have a non-trivial usecase, just use the best string representation for that. You don't need to use zero-terminated strings everywhere.
Use a macro like this for a dumb length-delineated string
struct MyString { const char *ptr; int length; };
#define S(stringlit) (struct MyString) { "" slit, sizeof slit - 1 };
Done!