Re:Zig in 30 Minutes
by WhoCaresLies on Sunday January 03, 2021 @05:10AM
(#25620841)
so it's not a type safe language if they use anonymous struct everywhere
also why ask for a parameter when it is not needed? print vs printf in C
Re:Zig in 30 Minutes
by AnIdiotOnTheNet on Sunday January 03, 2021 @10:15AM
(#25622189)
Anonymous struct/tuple/array is a convenience feature that can only be used for values.
Consider the above code without it:
std.debug.print("hello world!\n", struct{}{});
Now add a value: std.debug.print("{}!\n", struct{string: []const u8}{ .string = "hello world"});
Quite unwieldy. Zig used to have variadic functions and it was difficult to work with, complicated metaprogramming, and made how things work less obvious during reading. It was also pretty much only ever used for the "print" function.> so it's not a type safe language if they use anonymous struct everywhere
It's compile-time checked. The example shows a compile time error when the struct fields are not completed by the anonymous struct
The || syntax is used elsewhere in zig, if statements, catch, switch, etc.
There's no requirement for a function inside a struct to act on the contents of structs, so it's reasonable to use structs as namespaces. This is what is happening when you @import, for example. The imported file becomes a struct.
This is quite different from a lot of other PLs, but it is pleasantly consistent when you get used to it.
There is a usingnamespace keyword to make a structs public contents spill out into the current scope. It's to be used sparingly.
Edit: I'm wrong! It's an anonymous struct with number fields, not an anonymous array.