3 ms·
If we’re comparing C to Zig I’m not sure what memory safety even needs to be mentioned for. For C to Zig there’s plenty of reasons one might prefer Zig. For me
by helen___keller 3y ago
If we’re comparing C to Zig I’m not sure what memory safety even needs to be mentioned for.
For C to Zig there’s plenty of reasons one might prefer Zig. For memory safety obviously you might opt to choose neither.
- rayiner 3y agoIn a vacuum, one might prefer Zig. But given that everyone already knows C and the ecosystem is so highly developed, it takes a gamechanging feature like Rust's memory safety to make an alternative language attractive (beyond a "this is cool" project--which I totally support).
- helen___keller 3y agoThat is probably why Zig has such a focus on seamless C interop. There’s a good thread in these comments talking about this. Regardless, point taken. You’re more or less describing the internal fear I have (mentioned in another thread) that if I dedicate time to a nontrivial Zig project I will regret it if/when there’s no Zig community in N years
- alwaysbeconsing 3y agoI haven't tried Zig, but "all the things you like about C plus better versions of most/all of the awkward bits" seems like a reasonable value proposition. Especially since the compiler can apparently let you use C painlessly alongside your Zig -- enabling incremental rewriting.
- j-james 3y agoCan you use Zig painlessly alongside C? Does `zig cc` or an equivalent provide for writing Zig libraries that then can be called by a main C function?
- deleted 3y ago[deleted]
- helen___keller 3y agoYes probably as painlessly as a nonC language can get. First class support for C calling conventions, struct layouts, and so on https://ziglearn.org/chapter-4/ https://ziglearn.org/chapter-4/ See here
- j-james 3y agoYeah, I read through that: unless I'm missing something I think what I'm curious about is "calling C code from Zig and vice versa" in the to-be-written section. Nim also has support for `ctypes` and compiles to C as its main target: yet though its interop is powerful it lacks in ergonomics, formerly you had to manually wrap every function you wished to use and this was only recently fixed by a macro-heavy external library. I'm wondering what Zig does because IMO even if you have an excellent technical solution getting people to actually use it alongside C is hard, it has to be seamlessly seamless. Nim's C interop is rarely used outside of wrappers and it even more rarely is used to produce C libraries (though perhaps that's more a fault of incompatible type systems)
- TUSF 3y agoWith Zig, you just write something like: const c = @cImport({ @cDefine("SOME_MACRO", "1"); @cInclude("raylib.h"); }); Which translates the header files directly into Zig and allows you to call into them under whatever namespace you assigned them under. You even get completions (assuming you're using the language server)
- Gigachad 3y agoIf you are going to leave C, why take a half step when you could go the full way and end up with the better tool.