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.
Thanks for the explanation, but I don’t think you’ve sold me on .x
Think I’d rather do the Point{} syntax.
Because we've said x is a constant we're obliged to specify its type. For variables we're allowed to use inference and in most cases the type can be correctly inferred, but for constants or function signatures inference is deliberately prohibited.
const x: Rect = ....
[Note that in Zig what you've written isn't a constant, Zig takes the same attitude as C and C++ of using const to indicate an immutable rather than a constant]
Zig is planning to get rid of explicit `T{}` syntax, in favor of only supporting inferred types.
https://github.com/ziglang/zig/issues/5038
So the explanation of a dot standing in for a type doesn't make sense in the long run.