-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Change style guide for "namespaces" to be TitleCase #1884
Comments
Just to get a little preview of what this would look like: const Std = @import("Std");
pub fn main() !void {
// If this program is run without stdout attached, exit with an error.
const stdout_file = try Std.Io.getStdOut();
// If this program encounters pipe failure when printing to stdout, exit
// with an error.
try stdout_file.write("Hello, world!\n");
} |
I do think that looks nice. |
I propose that acronyms are capitalized in the traditional way when used in a TitleCase context. Ex: |
@jayschwa I broadly advise against that convention. You wind up with names like |
tl;dr; UpperCamelCase frustrates when using abbreviations or acronyms, which as it so happens, is the most popular for namespace-names. my 2 cents as a zig newcomer: NO to UpperCamelCase namespaces: Premise assumptions and broad strokes about a namespace-name:
Style-1 → currentstd.io.debug.warn()
cstr.toSlice()
json.Parser.init()
dynamic_library.LinuxDynLib.open()
Style-2 → UpperCamelCase as proposedStd.Io.Debug.warn()
Cstr.toSlice()
Json.Parser.init()
DynamicLibrary.LinuxDynLib.open()
Style-3 → UpperCamelCase and all-caps for { acronym }Std.IO.Debug.warn()
Cstr.toSlice()
JSON.Parser.init()
DynamicLibrary.LinuxDynLib.open() Style-4 → UpperCamelCase and all-caps { abbreviation/acronym }STD.IO.Debug.warn()
CSTR.toSlice()
JSON.Parser.init()
DynamicLibrary.LinuxDynLib.open() |
@mikdusan Acronyms already lose there casing in type names according to the current styling so unless you propose that this is also changed, then I don't see this as an argument against changing 'namespace' to be TitleCase. // Taken from the "Style Guide" section in Zig's documentation
// The word XML loses its casing when used in Zig identifiers.
const xml_document =
\\<?xml version="1.0" encoding="UTF-8"?>
\\<document>
\\</document>
;
const XmlParser = struct {
field: i32,
}; Type names rarely contain abbreviations so I don't know what is preferred here. I will say, that it is hard to argue for or against "appeal". It is very subjective and all I can really say here is, that I find
|
I don't think that's an argument for changing to TitleCase; rather the opposite; because the
There are many examples of TAR that work well and commonly, as either all-caps or all-lower-case, but (again subjectively) look awful when TitleCase'd.
I think there is a reason why those acronyms are seen in tech-print almost exclusively as TAR... if I may be so bold to suggest it's because the public at large, including programmers, find it easier. For whatever reason, it is easier and that has value.
My argument is not really about sticking to english rules. Rather it's that we understand it is a basis, and has influence over the readability of source code. It is a plus, I think, when we can keep some consistency to TAR.
On a side note, the rule as listed "current" doesn't appear to match Zig online docs. I read the docs like this:
Thank you Hejsil for responding. I'm pretty sure there isn't much more I can say except that I agree there is significant subjectivity. It's not clear to me that I'm late to the game on providing input, but regardless, I'm happy with the way Zig is progressing and whichever way this goes it won't be a show-stopper for me. |
@mikdusan You seem to have a good idea of common practices in these areas of writing. I would agree that I too tend to see this TAR style more often than not (I think, I don't keep track) when reading 'tech-print', but it doesn't seem to be a standard (I can't find any information about TAR). Wikipedia has a section about caps styles, and from what I can read here, the choice is mostly stylistic. I don't have the same source for abbreviations, but I think it's mostly a stylistic choice as well. I'd never write I also know that C# uses the proposed style for namespaces, but most languages similar to Zig uses snake_case (Rust, C++, Go). Edit: Also, you're not late at all on this issue. Until it has been accepted and applied, the discussion can and will continue :) |
I don't have a concrete counter proposal to this issue at the moment, but I want to say that I agree with @mikdusan's breakdown in #1884 (comment). I think it clearly demonstrates the pros/cons of status quo as well as this proposal. In particular, there are a few identifier names in the standard library that feel "wrong" according to status quo style guide (things like |
Here's an example from standard library that is awkward: pub fn setVerboseCC(self: *LibExeObjStep, value: bool) void {
self.verbose_cc = value;
} The lower case one looks good. "Verbose C Compilation". The camelCase one looks wrong, and But as is this example represents cognitive dissonance, because if the fn name and the field were to match, then it would have to be |
more 2¢; in consideration of article Camel case:
and those are some pretty good general rules. But it's not clear enough for more complex cases that coding runs into. The following guidance is more or less my preference style to clear things up:
These styles become much easier to visualize with a table. A good style guide would show simple, medium and complex examples to help readers reach the same naming conclusions. |
I think Some stdlib module names were |
Could a scope-resolution operator e.g. const std = @import("std");
pub fn main() !void {
// If this program is run without stdout attached, exit with an error.
const stdout_file = try std::io::getStdOut(); // getStdOut() accessed via :: because it doesn't take an implied *self param
// If this program encounters pipe failure when printing to stdout, exit
// with an error.
try stdout_file.write("Hello, world!\n");
} Pros:
Cons:
|
Why was this closed? Was it rejected? If so, what was the reason? I just want to make sure I'm staying up to date on what's going on with Zig and I feel like I missed something here. |
Yes, if a proposal is closed that means it is no longer being considered. Have a look at the comments in this thread. @mikdusan's comments in particular are quite clear. |
Relies on #1047 being implemented:
@typeOf(x) == type
orx
is a function returningtype
then x should be TitleCase"@typeOf(x) == type and std.meta.fields(x).len != 0
orx
is a function returning y where@typeOf(y) == type and std.meta.fields(y).len != 0
, then x should be TitleCase"TitleCase
name:Namespace.func()
snake_case
name:instance.method()
instance
is passed by copy,*const
or*
).Thing.func(&instance)
.snake_case
andcamelCase
names are taken up bystd
, keywords and my own namespaces (the following list is words I've wanted to use for variables and functions before, but couldn't without then prefixing my namespace).std
:mem
,json
,mutex
,event
,drawf
section
,align
,type
,and
,or
,export
,error
,catch
slice
,platform
,scan
,bits
,parser
,string
,compare
TitleCase
names are rarely declared, and single wordsnake_case
andcamelCase
names are extremely common.The text was updated successfully, but these errors were encountered: