New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
style guide: make enum and union fields snake_case the same as struct fields #2101
Comments
How about |
I'll note that @thejoshwolfe even before this proposal already broke from the style guide to do this: https://github.com/thejoshwolfe/legend-of-swarkland/blob/ace37864bf4754851bfe0c5256077171c2db695f/src-core/protocol.zig#L8-L28 I'll also note that the enums in |
for unions specifically, the options are very similar to fields, so matching the style of field names makes more sense than matching the style of type names. For enums, the options are most similar to global constants, and i believe the style there is snake case as well. For union enums, we have to choose one style for both. In no way does it make sense for the options to match the style of a type name. |
After months of silent deliberation and sleeping on it, this is now accepted. I'm in no hurry to break everybody's code, but this is the new style for the standard library. Exceptions:
|
Will this style be applied to errors too? (Tangentially related: #2647)
@Akuli I think that would be the right thing to do if the compiler style guide already had that e.g. for constants, but as of now it doesn't use that style for naming anywhere. |
No, I think errors can remain as is. |
One thing to consider is the The following example wont compile:
If i escape
This issue applies to std.json.Value. |
This follows the accepted change to the style guide: ziglang#2101
This follows the accepted change to the style guide: #2101
Currently we have this problem with
union(enum)
:zig/std/zig/ast.zig
Lines 110 to 130 in aff7b38
Now, if you use
Error.InvalidToken
are you referring to the type, or the enum value? It's ambiguous. This causes switch expressions to resort to awkward uses of@TagType
:zig/std/zig/ast.zig
Lines 133 to 141 in aff7b38
However if we had a different style guide, the enum value would be
Error.invalid_token
and the type would beError.InvalidToken
.This is less of a problem now that #683 is mostly solved, but there is still the ambiguity.
This sort of conflicts with #995.
The text was updated successfully, but these errors were encountered: