←back to thread

Zig is hard but worth it

(ratfactor.com)
401 points signa11 | 1 comments | | HN request time: 0s | source
Show context
helen___keller ◴[] No.36150396[source]
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

replies(5): >>36150507 #>>36150918 #>>36151708 #>>36155513 #>>36158163 #
kuroguro ◴[] No.36150507[source]
I 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.

replies(2): >>36150581 #>>36153145 #
eatonphil ◴[] No.36150581[source]
This 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/c...

Integration testing sample code: 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/c...

replies(1): >>36151035 #
rowls66 ◴[] No.36151035[source]
I am truly puzzled by this. I understood Zig to be a very low level language like 'C'. Why would you write scripts in it?
replies(1): >>36151084 #
eatonphil ◴[] No.36151084[source]
It'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.

replies(4): >>36151224 #>>36151600 #>>36152429 #>>36155338 #
rowls66 ◴[] No.36155338[source]
I guess I don't see C as programming language for writing scripts in either. In my view any language that requires a separate complication step is not a scripting language, and therefore not a language in which one writes scripts. In C or Zig you write programs.

Maybe I am just being too pedantic.

replies(3): >>36155537 #>>36159946 #>>36162472 #
1. Kamq ◴[] No.36159946{3}[source]
A number of languages that would have been traditionally compiled (statically typed, produce a native binary by default, etc), have started adding a "run" command.

If your language compiles fast enough, it's about the same experience as running a python script.