Link to Repo: https://github.com/JohnCosta27/Huffmanz Link to Video: https://www.youtube.com/watch?v=D5l5GUuNXB8&ab_channel=JohnCosta
Huffman Encoding is an algorithm for compressing text, using a binary tree to shorted the number of bits needed to represent each character. It’s one of the first algorithms I learned in Computer Science. I was 14 year old and in Year 9. But until recently it hadn’t crossed my mind again.
Then I found out about Zig. A new(ish) language where you manage your own memory, and have access to an incredible compiler that support
comptime, it’s an amazing (and extremely fast) language.
So I decided to learn both fully, and implemented a huffman encoding algorithm using the zig programming language. Up until this point I haven’t worked on a project in a language like zig, which requires memory management and everything that goes along with it. I have also never thought much about huffman encoding, but it’s a fairly simple algorithm so it was the perfect project to learn about this language.
I won’t go into much detail about Huffman Encoding, you can find many tutorials that do it better than I ever could. But I will talk about what I think about Zig.
I’m not a big language connoisseur, I like things that work, that are simple and have a friendly syntax, so I happen to love (Golang)[https://go.dev/], it’s simple, robust and very fast. It’s also garbage collected which is a plus.
I didn’t think I was going to be a big fan of Zig, my experience with C has been fine, but I haven’t loved it much, and I’ve never touched C++, but I really enjoyed it.
heap.zigfile in my repo to see what I’m talking about.
I would say I definitely would love to work more with Zig. It seems like the logical step forward for program that require the blazingly fast speed of no garbage collection. You can already see this happening in Bun.js, which seems to have great speed advantages (sometimes) compared to Node.js or Deno (even though both are written in a low level language).
Thank you for reading, if you would like to chat with me. You can email me at
[email protected]. Or visit my GitHub profile.