Zig in Depth Video Series

Hey dudes! :^) I’m creating this video series for those wishing to learn Zig step-by-step. I’m still covering very basic topics, but already have more than a dozen videos in the series so I think it can already be a useful learning tool. Hopefully it’ll be useful to someone.


I am binge-watching it whenever I got time. Fantastic collection of video tutorials. Many thanks to @dude_the_builder for putting time and effort into the series !!!

Regarding the video about Error handling in Zig I would like to understand what is the idiomatic way of propagating error context through the call stack. Zig does not provide error context in the language by design (no allocations are forced upon a user). But in case one needs it, what are the options? I am only familiar with a method where error context is put into ListArray(u8) and passed around as a function parameter.

1 Like

Thank you for watching the videos and your kind feedback. Regarding error context, you’re on the right track when realizing that to have a more elaborate error context mechanism would surly require some type of behind-the-scenes allocation or some other global state mechanism. I think that’s why Zig leaves this to the programmer to figure out instead. Passing around mutable state as a parameter as you mention is one option, as well as having global state to record error info (protected by mutex or atomics in multi-threaded code), and having some utility functions that take error values and take different actions depending on them (pretty much like in C) is what comes to my mind. I’m not aware of any specific idiomatic way of dealing with error context. Like many things in Zig, the language provides the tools for rolling your own solution. But maybe in the future this will be addressed as part of the language or standard library.

Awesome stuff! Made an account just to say thanks for putting in all the comptime examples! Until now, I hadn’t quite grasped that everything you illustrated was possible with comptime.

If you make more, I’d love to see Zig versions of common things in other languages. E.g. What are common Zig alternatives to interfaces? (I came across this talk on the subject[0], but I’m always interested in more common Zig patterns). Then there are other topics like using debug tools and profiling Zig code that I would be interested in watching.

[0] https://youtu.be/AHc4x1uXBQE?si=6HY5JNMOEfIubGF2

1 Like

For interfaces there is also this great blogpost from loris: Easy Interfaces with Zig 0.10.0 - Zig NEWS

For debug/profiling tools you can basically just use the same ones as for C/C++. I use AMD uProf and sometimes gdb for example and they work great with Zig.

Additionally Zig already has tons of debug checks active in debug mode, like undefined behavior checks, leak checks when using the GeneralPurposeAllocator and also a thread sanitizer which can detect data races(although that is currently broken on master). So you rarely need third party debugging tools.

1 Like

Hey, thanks for the positive feedback! Those are some great topic ideas for future videos. Once I cover most of the language itself and some highlights of the standard library, I’ll be looking into those types of topics for sure.

There is a very recent tutorial on interfaces in Zig by Karl Seguin (aka openmymind) [0]. While you are there, pock around other of his zig tutorials [1] that IMHO are among the best Zig learning materials available anywhere.

[0] Zig Interfaces
[1] https://www.openmymind.net/