logoalt Hacker News

phplovesonglast Sunday at 4:08 PM2 repliesview on HN

I find Zig syntax noicy. I dont like the @TypeOf (at symbol) and pals, and the weird .{.x} syntax feels off.

Zig has some nice things going on but somehow code is really hard to read, admitting its a skill issue as im not that versed in zig.


Replies

dsegolast Sunday at 9:40 PM

Zig is noisy and and the syntax is really not elegant. One reason I like odin's syntax, it's minimal and so well thought out.

flohofwoelast Sunday at 4:20 PM

The dot is just a placeholder for an inferred type, and IMHO that makes a lot of sense. E.g. you can either write this:

    const p = Point{ .x = 123, .y = 234 };
...or this:

    const p: Point = .{ .x = 123, .y = 234 };
When calling a function which expects a Point you can omit the verbose type:

    takePoint(.{ .x = 123, .y = 234 });
In Rust I need to explicitly write the type:

    takePoint(Point{ x: 123, y: 234);
...and in nested struct initializations the inferred form is very handy, e.g. Rust requires you to write this (not sure if I got the syntax right):

    const x = Rect{
        top_left: Point{ x: 123, y: 234 },
        bottom_right: Point{ x: 456, y: 456 },
    };
...but the compiler already knows that Rect consists of two nested Points, so what's the point of requiring the user to type that out? So in Zig it's just:

    const x = Rect{
        .top_left = .{ .x = 123, .y = 234 },
        .bottom_right = .{ .x = 456, .y = 456 },
    };
Requiring the explicit type on everything can get noisy really fast in Rust.

Of course the question is whether the leading dot in '.{' could be omitted, and personally I would be in favour of that. Apparently it simplifies the parser, but such implementation details should get in the way of convenience IMHO.

And then there's `.x = 123` vs `x: 123`. The Zig form is copied from C99, the Rust form from Javascript. Since I write both a lot of C99 and Typescript I don't either form (and both Zig and Rust are not even close to the flexibility and convenience of the C99 designated initialization syntax unfortunately).

Edit: fixed the Rust struct init syntax.

show 3 replies