Zig's Lovely Syntax
matklad.github.io
Zig's Lovely Syntax
1–10 of 246 posts
Re: Zig's Lovely Syntax
#2I've heard the argument that people might confuse binary operators for prefix/postfix operators, but I don't buy it. Who would think an operator named `orelse` is anything but binary?
Re: Zig's Lovely Syntax
#3Zig 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.
Re: Zig's Lovely Syntax
#4Since we're talking syntax... it's mildly infuriating that the zig parser is not smart enough to understand expressions like `const x=a()orelse b();`. You have to manually add a space before `orelse` -- but isn't that what `zig fmt` is for? I have RSI and it's maddening having to mash the arrow keys and add/remove whitespace until the parser is happy. I've heard the argument that people might confuse binary operators…
Re: Zig's Lovely Syntax
#5Re: Zig's Lovely Syntax
#6Re: Zig's Lovely Syntax
#7In my experience, everyone finds the syntax of their favourite language lovely - I love (mostly) C++.
Re: Zig's Lovely Syntax
#8This surprises me (as a C++ guy). I use lambdas everywhere. What's the standard way of say defining a comparator when sorting an array in Zig?
Re: Zig's Lovely Syntax
#9I 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.
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.
Re: Zig's Lovely Syntax
#10After all, Rust's big success is hiding the spinach of functional programming in the brownie of a systems programming language. Why not imitate that?