7 ms·
This is what I have struggled to understand about Zig. It seems pretty much like C in a mental model aspect - you are responsible for everything. It's slightly
by ashikns 1y ago
This is what I have struggled to understand about Zig. It seems pretty much like C in a mental model aspect - you are responsible for everything. It's slightly better than C, but C already runs on everything on the planet and can be made secure even if painfully so. So what niche is Zig aiming to fill?
- throwawaymaths 1y agono, null pointers are enforced safe at the type level in zig, as are array bounds, this eliminates huge classes of errors, so you are not "responsible for everything". unlike c, you often (unless highly tuned performance is needed) do not have to resort to opaque void pointers, and the compiler gives you typesafety on that, another major footgun in c. also operators and integer types are unambiguous, and there is no UB in safe compilation modes. It's arguably much better than C, not "slightly better than C"
- deleted 1y ago[deleted]
- uecker 1y agoIf you write a modern style of C, you can have bounds checked code and do not need to use void pointers. I usually find that people overestimate the advantages of newer languages compared to using C by comparing to old and badly written C.
- throwawaymaths 1y agoGP: "you are responsible for everything" AKA You are responsible for opting into "modern C". In order to be unsafe in zig (in the dimensions I mentioned) you must opt out.
- uecker 1y agoYou would need to opt-in into zig first, which is more effort than opting into modern C when you come from C.
- throwawaymaths 1y agoi suggest you show this thread to a neutral third party and ask them if your line of argument makes sense.
- uecker 1y agoConsidering that basically nobody uses Zig, I think most neutral third-parties seem to agree.
- accelbred 1y agoI used Zig for my projects for a while, but moved back to C for similar reasons. C23, with gcc extensions, and using MISRA-like coding style where it makes sense, provides a similar experience to Zig but with seamless C interop. You dont have comptime, but my biggest lesson from my time in Zig is that I usually want to pass a vtable instead of monomophizing over input types.
- barddoo 1y agoZig detects memory leaks pretty well when you build it using -Doptimize=Debug.