> Initializing arrays is weird in Zig. Lets say you want to have a 0 initialized array, you declare it like [_]u8{0} * 4 which means I want an array, of type u8, that is initialized to 0 and is 4 elements long. You get used to the syntax, but it’s not intuitive.
Alternatively:
var some_array = std.mem.zeroes([4]u8);
Though as mentioned later in the article the standard library documentation is not very good, making this not as obvious as it could be.> Everything in Zig is const x = blah;, so why are functions not const bar = function() {};?
Good question, there's an accepted proposal to fix this: https://github.com/ziglang/zig/issues/1717
> The builtin compiler macros (that start with @) are a bit confusing. Some of them have a leading uppercase, others a lowercase, and I never did work out any pattern to them.
In idiomatic zig, anything that returns a type is uppercased as though it were itself a type. Since only a few builtins return types, the vast majority of builtins will start with a lowercase letter. I think it is only `@Type`, `@TypeOf`, `@This`, and `@Frame` that don't.
Any recommendations on learning more about what constitutes idiomatic zig? This is an issue I have with learning any new language - it’s kind of hard for me to figure out what writing idiomatic code in that language looks like. I usually go looking for popular/high quality projects and reading that code but it takes away from the experience of actually just toying around not to mention it being hard knowing what a high quality project is. Thanks in advance!
I don't think of this as an idiomaticity guide.
There is "Ziglings", but those are a collection of small exercises with answers rather than a full guide.
https://github.com/ratfactor/ziglings
If you know of better resources than these two, please do share (not being passive aggressive here).