←back to thread

Zig is hard but worth it

(ratfactor.com)
401 points signa11 | 2 comments | | HN request time: 0s | source
Show context
WhereIsTheTruth ◴[] No.36156718[source]
The issues I have with Zig are similar to the ones I have with Rust, the syntax.. I will never get used to it, I find it tasteless and non-ergonomic

But, I manage to set it aside because it provides enough benefits, I mainly use Zig as a toolchain to crosscompile my libraries.. and write some helper externs

Hopefully they manage to improve and ease out the syntax by 1.0, I have hopes

replies(1): >>36156761 #
1. jadodev ◴[] No.36156761[source]
Have any examples of syntax you find tasteless? Things in Zig that feel ergonomic to me: comptime params > separate generic args; ptr.* > *ptr; optional pointers > possibly null normal pointers; separate syntax for slices, arrays, & pointers > 1 syntax for ptr & arrays.
replies(1): >>36157788 #
2. WhereIsTheTruth ◴[] No.36157788[source]

  var t: ?i32 = null;

  if (t) {

      t +=1;

  }

This for example doesn't work, you have to capture, many little things like that that stacks up and ends up creating a non-ergonomic syntax

No for loop, so you have to do multilines things like, and now you meet a new : construct, this pseudo for loop now looks confusing to look at

  var i: i32 = 0;

  while (i < 42) : (i+=1) {

  }

Then constant casting between integers, and also floats.. also no operator overload for the math types etc..

Also not a fan of the pointer difference between [] * [:0], too much different nitpicking that makes iterating slow and painful, I understand the benefits, but the way it's done is not enjoyable, at least to me

That's just whats on the top of my head, it's been a while I haven't wrote Zig code so I may be remembering wrong