|
|
|
|
|
by rslabbert
1863 days ago
|
|
Not a Zig expert, but safety is a factor for Zig, it just treats it as less of an absolute than Rust. I think the thing to keep in mind is that something can be a priority without being an absolute priority. I'd make a comparison to OpenBSD vs Linux. Both have security as a priority, OpenBSD just has a more absolute focus on it. For example, a couple of features come together really nicely to make memory safety easier to test in Zig:
* You need a reference to an Allocator to be able to allocate memory, so as a general rule, the caller can control which allocator is used.
* Unit testing is integrated well into the language.
* Therefore, you can create an allocator for each unit test, and fail the test at the end if any memory was leaked.
* This process can also happen at the application level with the General Purpose Allocator, which can let you print an error when the program exits if anything was leaked. The above doesn't solve every memory safety problem (and there are other features like native bounds-checked slices that solve other kinds of issues), but it provides an extra layer that can probably get us quite far into the "quite safe" camp. |
|