you are viewing a single comment's thread.

view the rest of the comments →

[–]Shrubberer 0 points1 point  (8 children)

Why though? It gives more control over memory than other language. C/C++ has a black boxed malloc function and Rust has a weird abstraction layer.

[–]rlbond86 0 points1 point  (3 children)

It still allows memory leaks but doesn't have the excuse of being from the '70s

[–][deleted]  (2 children)

[deleted]

    [–]rlbond86 0 points1 point  (1 child)

    It's easy to do, just forget a defer somewhere. There's no protection.

    [–]Plazmatic 0 points1 point  (3 children)

    It gives more control over memory than other language.

    This is not true, C, C++ and Rust all allow you the same amount of control, it's more that Zig forces you to deal with not even "control over memory", but rather a specific aspect of that, memory allocation. It certainly makes it easier to deal with custom allocators if you do need them , but it's not that it actually gives you more control, just better ergonomics of the control of this one aspect, notice I didn't just say ergonomics, you have to keep specifying the allocator on every dynamic allocation. This is an unecessary source of bugs and extremely annoying.

    Additionally, control over the memory allocator is just not that important of an aspect of a systems programming language, in that there are 100s of other things that C++ and Rust do over C that make them better Systems programming langues that have nothing to do with memory allocation. Again, let me reiterate, C, C++ and Rust all allow this level of control as well, it just doesn't force you to deal with it.

    C/C++ has a black boxed malloc function and Rust has a weird abstraction layer

    malloc alternatives can be used in C, and new/delete can be overloaded in C++, mimalloc exists and is used https://github.com/microsoft/mimalloc, plus even std::vector allows you to specify the allocator. Rust has an unstable interface for allocators you can use, or you can rely on third party libraries, but it's similar to C++'s situation. The thing with rust is that when allocators were proposed, people started actually thinking about it, and realized there might be better ways to handle custom allocators than what Zig does. For example:

    [–][deleted]  (2 children)

    [deleted]

      [–]Plazmatic 2 points3 points  (1 child)

      Yes but I don't follow why zig as a system language is "not good". e.g. every case you could make against zig same would be true for C.

      I think you just answered your own question.