<story><title>Zig, parser combinators, and why they&apos;re awesome</title><url>https://devlog.hexops.com/2021/zig-parser-combinators-and-why-theyre-awesome</url></story><parent_chain><item><author>Jakobeha</author><text>I see a lot of articles posted on HN about Zig. What&amp;#x27;s so special about Zig, and how does it fill its own niche with other languages like Go and Rust?</text></item></parent_chain><comment><author>lhorie</author><text>As far as I know, zig is the only language that is able to output binaries on par in size w&amp;#x2F; C (a hello world in zig is about the same size as a C one, whereas most other languages can only manage at a minimum an order of magnitude bigger binaries, sometimes several orders of magnitude). Zig interops cleanly w&amp;#x2F; C ABI and C toolchains, can also cross compile AND &lt;i&gt;can cross compile C proper&lt;/i&gt;. You can even drop all the way down to asm (standard C technically doesn&amp;#x27;t support this).&lt;p&gt;I often refer to zig as a &amp;quot;very sharp knife&amp;quot;: it&amp;#x27;s &amp;quot;cool&amp;quot; for new languages to have more safeguards to protect you from yourself, but Zig feels a bit like it goes in opposite direction in the sense that it exposes the underlying plumbing more than most languages. For example, Go and Rust memory allocations and memory layout are fairly opaque; in zig you can control it idiomatically with obsessive precision.&lt;p&gt;But unlike C, zig offers a host of safety features, like integer overflow checks, compiler-checked optionals and exhaustive switch, as well as a well behaved compile-time system, and a bunch of syntactical sugar (&amp;quot;method&amp;quot; syntax, if&amp;#x2F;while&amp;#x2F;block&amp;#x2F;return expressions, etc).&lt;p&gt;And unlike C++, zig is a very small language.</text></comment>
<story><title>Zig, parser combinators, and why they&apos;re awesome</title><url>https://devlog.hexops.com/2021/zig-parser-combinators-and-why-theyre-awesome</url></story><parent_chain><item><author>Jakobeha</author><text>I see a lot of articles posted on HN about Zig. What&amp;#x27;s so special about Zig, and how does it fill its own niche with other languages like Go and Rust?</text></item></parent_chain><comment><author>anderspitman</author><text>I&amp;#x27;ve written a decent amount of Rust and Go. The reason Zig is on my watch list is because I see it as a potentially better (ie faster) Go, or C+=1. Go handles most of my needs, but the way I write it tends to involve a decent amount of manual resource management (mostly mutexes), so I don&amp;#x27;t see the manual memory management in Zig as a big downside.&lt;p&gt;Rust is a great language, and I love it, but it&amp;#x27;s hard for me. Writing in Rust reminds me a lot of test-driven development. It gives me such a great feeling of safety and control over your process, but at the end of the day it can be very tedious. The real killer is when I&amp;#x27;m trying to prototype. If I don&amp;#x27;t already know what my interfaces are going to look like, Rust really slows me down. Compile times don&amp;#x27;t help here either.&lt;p&gt;If I were implementing a well-known protocol and had a general idea of how to architect it, or just really needed it to be rock solid, I would strongly consider Rust first. I&amp;#x27;ve been working on a lot of protocol design the last couple years so it&amp;#x27;s been more prototype-heavy.&lt;p&gt;Note that most of my Rust experience involved pre-async&amp;#x2F;await asynchronous networking code. I&amp;#x27;m sure it would be a better experience for me now. I should also note that programming in Rust yields some &lt;i&gt;very&lt;/i&gt; magical moments, such as parallelizing loops by changing a single line. It&amp;#x27;s a special language, and not going anywhere. I hope to find reasons to use it again in the future.&lt;p&gt;EDIT: Oh, another place Zig may have a big advantage over Go is binary sizes, particularly for things like WebAssembly.</text></comment>