<story><title>Learning Zig</title><url>https://www.openmymind.net/learning_zig/</url></story><parent_chain><item><author>satvikpendem</author><text>What are the pros and cons of Zig vs Rust? I see Zig mentioned more and more here, especially with regards to threads about Bun, the largest &amp;#x2F; most popular project in Zig currently, but I&amp;#x27;m not sure why I should use it over Rust. Zig seems like it still does not solve the problem of memory safety, in that it has safety issues that would be caught by a borrow checker or other such memory safety checker [0]. You can still use after free, for example:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    var hello = try allocator.dupe(u8, &amp;quot;hello world&amp;quot;);
    allocator.free(hello);
    std.debug.print(&amp;quot;{s}\n&amp;quot;, .{hello}); 
&lt;/code&gt;&lt;/pre&gt;
[0] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;www.scattered-thoughts.net&amp;#x2F;writing&amp;#x2F;how-safe-is-zig&amp;#x2F;&quot; rel=&quot;nofollow noreferrer&quot;&gt;https:&amp;#x2F;&amp;#x2F;www.scattered-thoughts.net&amp;#x2F;writing&amp;#x2F;how-safe-is-zig&amp;#x2F;&lt;/a&gt;</text></item></parent_chain><comment><author>flohofwoe</author><text>In terms of safety, Zig is somewhere in the middle between C and C++ on one side, and Rust on the other side (e.g. it enforces much more correctness than C or C++, and has runtime spatial, but not temporal memory safety (but it has a debug allocator which doesn&amp;#x27;t recycle memory (or rather: address ranges) and which should catch most temporal memory safety problems - like your example).&lt;p&gt;Zig doesn&amp;#x27;t have separate sublanguages for macros and generics, instead these are all handled with regular &amp;#x27;comptime&amp;#x27; Zig (along with type reflection).&lt;p&gt;Zig has builtin syntax sugar for dealing with optionals and error unions, which makes code less noisy (although that may be subjective - and I think Rust also got some of that over time).&lt;p&gt;Zig&amp;#x27;s interaction with the C world is excellent, and to a lesser degree also to the C++ and ObjC world (the Zig compiler can compile C++ and ObjC code, but still requires a C shim to sit between Zig and C++ or ObjC code).&lt;p&gt;Zig has much less influence from high level functional languages and less &amp;quot;type system wankery&amp;quot; compared to Rust, this again is a good thing for some people, while disliked by others.&lt;p&gt;A minor detail, but which I think demonstrates the Zig philosophy: the Zig compiler executable is also the build system and package manager. In Rust this is delegated to a separate tool (cargo).&lt;p&gt;...and my personal opinion: Zig is a lot more &amp;#x27;elegant&amp;#x27; than Rust which results in more joy when writing Zig code. Rust feels entirely too much like &amp;#x27;designed by committee&amp;#x27;. With Zig I &amp;quot;grokked&amp;quot; the language in a weekend of tinkering, while with Rust I never really had &amp;quot;fun&amp;quot; despite several attempts of trying to like it.&lt;p&gt;TL;DR: If I had to create an absolutely waterproof and critical isolated piece of code, I would probably write that in a &amp;quot;simple Rust subset&amp;quot;. For anything else I would definitely prefer Zig.</text></comment>
<story><title>Learning Zig</title><url>https://www.openmymind.net/learning_zig/</url></story><parent_chain><item><author>satvikpendem</author><text>What are the pros and cons of Zig vs Rust? I see Zig mentioned more and more here, especially with regards to threads about Bun, the largest &amp;#x2F; most popular project in Zig currently, but I&amp;#x27;m not sure why I should use it over Rust. Zig seems like it still does not solve the problem of memory safety, in that it has safety issues that would be caught by a borrow checker or other such memory safety checker [0]. You can still use after free, for example:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    var hello = try allocator.dupe(u8, &amp;quot;hello world&amp;quot;);
    allocator.free(hello);
    std.debug.print(&amp;quot;{s}\n&amp;quot;, .{hello}); 
&lt;/code&gt;&lt;/pre&gt;
[0] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;www.scattered-thoughts.net&amp;#x2F;writing&amp;#x2F;how-safe-is-zig&amp;#x2F;&quot; rel=&quot;nofollow noreferrer&quot;&gt;https:&amp;#x2F;&amp;#x2F;www.scattered-thoughts.net&amp;#x2F;writing&amp;#x2F;how-safe-is-zig&amp;#x2F;&lt;/a&gt;</text></item></parent_chain><comment><author>grayhatter</author><text>You shouldn&amp;#x27;t use it over rust... that&amp;#x27;s a nonsensical question. That&amp;#x27;s like asking when you should use a hammer instead of a screwdriver.&lt;p&gt;I use zig because it&amp;#x27;s enjoyable to use. I hate writing rust, it feels like the language is actively fighting me. I started writing zig, and started loving the process of simplify writing code again. Zig is nice because, to steal their quote. I&amp;#x27;m able to spend my time debugging my code, and not debugging my understanding of the language. I&amp;#x27;ve stepped on a use after free but because it&amp;#x27;s &lt;i&gt;so&lt;/i&gt; easy to write and use tests, I found it and fixed it in tests.&lt;p&gt;Bugs are undesirable, but I can write just as many bugs in rust. So I&amp;#x27;m always so confused about why rust users are so panicked about use after free, or other memory bugs. Like somehow the only bugs rust has a handle on is the worst class of bug? Such an odd idea I can&amp;#x27;t figure out...</text></comment>