5 ms·
What advantages would there be with a native string type over []const u8. (For those not fluent in zig, a string is typed as a slice constant bytes, where a sli
by pyrolistical 3y ago
What advantages would there be with a native string type over []const u8. (For those not fluent in zig, a string is typed as a slice constant bytes, where a slice is a pointer + length)
- Ygg2 3y agoAn UTF8 String would have invariant of always having valid UTF8, omitting need for further UTF8 validation. If you're working on bytes string in Zig the status of them is unknown, so you have to always validate even if it's just Utf8. In Rust you can omit Utf8 validation for bytes from a String.
- slimsag 3y agoIn Zig strings are assumed to be UTF8 unless documented otherwise, so any function operating on strings is not wasting CPU cycles doing any validation. The person who creates the string is expected to ensure it is valid UTF8 if needed.
- tialaramex 3y agoThis is the "Just don't write bugs" that we laugh at for C and C++.
- Ygg2 3y agoIf there is one thing Ada does better than Rust, is that it encodes the invariants in the type system. While Rust doesn't goes as far as I would have want it's miles better than what Zig and C are doing - the programming equivalent of "Trust me bro!".
- binary132 3y agoConstructing a runtime-invariant-checked utf8 string is not "omitting utf8 validation".