What are the styling standards for zig

What are the specific styling standards when it comes to writing zig code:

  • Is it better to have a function return a created struct, have the struct be @This() or to have an init method in the struct, or is it all up to choice.
  • What naming conventions are used for different things, I typically PascalCase structs, enums all that sort of stuff in other languages and snake_case functions and variables. Is it any different in zig?

If there are any other sort of styling guidelines I missed still feel free to let me know, just want to make sure I write zig code the community won’t hate :slight_smile:

I suggest you take a look at this section of the docs to begin with. And complement that with looking at the source code for the Zig standard library.

1 Like

I’ve been looking at the source code for the zig std, however it has made me more confused for structs as some use @This and some use returning a struct. For structs does it really matter how you do it?

I usually write code that packs more than one struct inside the same file, so I don’t really take advantage of the “file is an implicit struct” thing. I am not saying this is the best way… Maybe for the next AoC I will switch to @This – who knows, perhaps I decide it is much better.

1 Like