[kwlug-disc] Go vs Zig

Doug Moen doug at moens.org
Fri Oct 11 07:28:57 EDT 2024


Zig is a low level system programming language that is designed for high performance. Like assembly language, nothing happens implicitly, everything that happens is because of code that you explicitly wrote. Implicit code makes it harder to reason about performance because you can't see what the machine is doing.

This includes memory allocation: in Zig you explicitly allocate memory with a function call, and you explicitly free it, like in C. In Go, there is a garbage collector that automatically frees unreferenced memory objects. In C++ and Rust, there are reference counting smart pointers that automatically increment and decrement reference counts, freeing the object when the reference count is decremented to zero. These features are not permitted in Zig.

If you want a string type, you should use a higher level language. Neither Zig nor Go have a proper string type. In both languages, UTF-8 strings are represented by arrays of bytes, and the byte array type can contain arbitrary bytes, it's not restricted to UTF-8. Indexing into a byte array gives you the i'th byte, not the i'th Unicode character.

Doug.

On Fri, Oct 11, 2024, at 4:17 AM, William Park via kwlug-disc wrote:
> Just as I was planning to dive into Go over the weekend, someone in the 
> list mentioned Zig.  So, I browsed a bit.
>
> Why should I learn Zig when it doesn't even have "string"?
> -- 
>
> _______________________________________________
> kwlug-disc mailing list
> To unsubscribe, send an email to kwlug-disc-leave at kwlug.org
> with the subject "unsubscribe", or email
> kwlug-disc-owner at kwlug.org to contact a human being.



More information about the kwlug-disc mailing list