6 ms·
My main issue with Zig is that I’m scared to invest time in writing something nontrivial to see the community/adoption flounder then regret not using Rust or C+
by helen___keller 3y ago
My main issue with Zig is that I’m scared to invest time in writing something nontrivial to see the community/adoption flounder then regret not using Rust or C++ later
The language itself is fun. The explicit-ness of choosing how allocation is done feels novel, and comptime is a clean solution for problems that are ugly in most languages.
Aside from lack of community I’d say the biggest nuisance is error handling in nearly everything including allocations. I get that allocation can fail but the vast majority of programs I write, I just want to panic on an allocation failure (granted these aren’t production programs…)
Edit: in retrospect, allocator error handling verbosity is probably necessary due to the power the language gives you in choosing allocators. If I use the general purpose allocator then my edge case is PC out of memory; if I use a fixed buffer allocator, a failed allocation is a code bug or a common error case, so we might want to handle the failed allocation and recover
- kuroguro 3y agoI suppose you could write a few line wrapper that panics :) But yeah, most of the time I don't even want to think which allocator to use let alone handle it's errors.
- eatonphil 3y agoThis is basically what I've come to do in the Zig scripts I write at work. It took a bit of getting used to when I joined but we agreed as a team to have all meaningful scripts written in Zig not bash (for one, bash doesn't work on Windows without WSL and we need to support Windows builds/testing/etc.). It makes about as much sense as any other cross-platform scripting option once I got used to it! Some examples: Docs generation: https://github.com/tigerbeetledb/tigerbeetle/blob/main/src/clients/docs_generate.zig https://github.com/tigerbeetledb/tigerbeetle/blob/main/src/c... Integration testing sample code: https://github.com/tigerbeetledb/tigerbeetle/blob/main/src/clients/integration.zig https://github.com/tigerbeetledb/tigerbeetle/blob/main/src/c... Running a command wrapped in a TigerBeetle server run: https://github.com/tigerbeetledb/tigerbeetle/blob/main/src/clients/run_with_tb.zig https://github.com/tigerbeetledb/tigerbeetle/blob/main/src/c...
- rowls66 3y agoI am truly puzzled by this. I understood Zig to be a very low level language like 'C'. Why would you write scripts in it?
- eatonphil 3y agoIt's significantly nicer to write than C (my opinion obviously). I see it as a general purpose language. But mostly the team decided to do this because we wanted to unify on one language and double down on the investment in Zig. I'm not a fanboy (nothing wrong if anyone is, just clarifying about myself); I think this choice was right.
- vaughan 3y agoI'm moving all my scripting to TypeScript using Bun (JS runtime written in Zig). For scripting its a way better choice. `bun:ffi` also makes it trivial to run C or Zig code when you need to.
- 59nadir 3y agoFor what it's worth I think this is an excellent choice. Back in 2019 I was deciding whether I wanted to pursue Zig full-time and one of the upsides that I determined was that once you reach critical mass writing all of your code for tools and things in Zig you end up with things that are really exactly what you need and with a very high baseline for speed, flexibility, and so on. Right now I'm considering the same thing but with Odin and for many of the same reasons that I had for Zig; it's an excellent language to write foundational code in and once you do, you end up being able to build significantly more understandable, reliable, stable and consistent things. This, but on a company level, is a real multiplier. Once you adopt a couple of Python scripts and that's OK, you give up the possibility of wielding this sharp spear. Edit: I think "How I program C" by Eskil Steenberg is an interesting window into what you can get if you laser focus on a language and environment and allow yourself to build up a mountain of code that you dogfood: https://www.youtube.com/watch?v=443UNeGrFoM https://www.youtube.com/watch?v=443UNeGrFoM At some point I will likely soft-retire and at that point it's exceedingly unlikely that I'll bother with using other people's libraries except a few key ones that I think are decent, and at that point there really is no reason I'd sit down and write these fundamentals in anything but a lower-level language. Odin, Zig or something like it would pretty much be the only thing on the table.
- chrsig 3y agoI think for the problem space zig is trying to fit in, it's pretty essential to have custom allocator support thoroughly baked in. It's the sort of thing that lets a data structure be used on both a gpu and cpu, allocation out of shared memory, or ensure that no dynamic allocations are happening at all. Most programs don't have those concerns - so zig may not be the best choice for them. For the programs that do have those concerns, forethought about allocators is pretty important. Right tool for the job, and all that.
- distcs 3y ago> If I use the general purpose allocator then my edge case is PC out of memory What does PC mean in this context?
- nativecoinc 3y agoMaybe "the whole computer is out of memory" (general purpose allocator). Contrast with a custom allocator which might only be able to work with a few kilobytes (for example).
- helen___keller 3y agoPersonal computer
- kubanczyk 3y agoplayer character
- loeg 3y ago> Aside from lack of community I’d say the biggest nuisance is error handling in nearly everything including allocations. I get that allocation can fail but the vast majority of programs I write, I just want to panic on an allocation failure (granted these aren’t production programs…) The C strategy for this was just to wrap malloc() with something called xmalloc or malloc_nofail or whatever: void *malloc_nofail(...) { void *res = malloc(...); if (res == NULL) { abort(); } return res; } (Or whatever.) The same would work in Zig, I think.
- helen___keller 3y agoYes you can easily make a one liner allocation function in zig that takes an allocator as input with a comptime type and panics if allocation fails and returns the unwrapped allocation I just say nuisance because zig code often looks like Go code in that almost every return type becomes an error union as allocation error handling (and maybe other errors) trickle up
- TylerE 3y agoFrom my experience with Zig (limited but not zero) it seems like an ok solution to a problem I don't have, and don't forsee having.
- faitswulff 3y agoMy impression of the Zig language as a total outsider is that it seems like it has the underpinnings of success: it has a niche, it has a governance model, and it has real commercial users. It just has to not blunder very hard on the way to some level of promised stability.
- bsder 3y ago> My main issue with Zig is that I’m scared to invest time in writing something nontrivial to see the community/adoption flounder then regret not using Rust or C++ later This is 100% a real concern. If I'm going to choose Zig, it's because it is SO much better on some axis that the community/adoption isn't an issue as I gain the benefits almost immediately. That means that C++ and Rust probably aren't in the scope of choice anyway. I especially like the comment from elsewhere in thread where they are using it for scripting, of all things, because they can pop out code that builds and works on Windows and Linux. That's a good example--you gain the benefits immediately even if you later have to unwind that to something like Python.