4 ms·
Here are some features of Zig that make debugging much easier than C++: * safety checks (equivalent to UBSAN) when triggered, print stack traces that include s
by AndyKelley 4y ago
Here are some features of Zig that make debugging much easier than C++:
* safety checks (equivalent to UBSAN) when triggered, print stack traces that include source code lines and point to the relevant line/column
* one of the safety checks is using the wrong field of an untagged union. This one is so underappreciated. Wrong union field access costs so much time to debug in C++ but it is a breeze in zig, you get a crash explaining the problem with a stack trace immediately, not a corrupt value that causes problems down the road. untagged unions are core part of the strategy that makes zig fast & have a small memory footprint.
* valgrind client request integration[1]. valgrind "just works" better with Zig than C/C++ because zig emits communicates more information about memory regions that are "undefined".
* error return tracing [2]
* segfaults print stack traces
* std.debug has features to collect stack traces in a compact manner and then dump them at a relevant time [3]
* std.heap.GeneralPurposeAllocator detects leaks and prevents memory corruption from Use-After-Free/Double-Free, making debugging easier
[1]: https://valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.clientreq https://valgrind.org/docs/manual/manual-core-adv.html#manual...
[2]: https://ziglang.org/documentation/master/#Error-Return-Traces https://ziglang.org/documentation/master/#Error-Return-Trace...
[3]: https://github.com/ziglang/zig/blob/4a98385b0aa3808ab05a1ebfbc90fd0bcd97c0d9/lib/std/debug.zig#L1941-L2038 https://github.com/ziglang/zig/blob/4a98385b0aa3808ab05a1ebf...
- llimllib 4y agoThanks!