Skip to content
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

proposal: remove pub from the language #21503

Closed
gooncreeper opened this issue Sep 24, 2024 · 3 comments
Closed

proposal: remove pub from the language #21503

gooncreeper opened this issue Sep 24, 2024 · 3 comments

Comments

@gooncreeper
Copy link

gooncreeper commented Sep 24, 2024

edit: I now disagree with this proposal as I now realize (after using the language a lot more) that pub is actually quite useful for documentation.

@paperclover
Copy link
Contributor

i've sometimes wanted handles to private functions, but if i recall any of those moments, they are all trying do something i should not have. in the rare case it does, just mark it pub!

a more objective reason this is a bad idea is to do with imports, as they are just decls initialized with @import, it would mean they all become public re-exports. which is terrible. consider that this code would now function, since const windows in posix.zig and const mem in windows.zig would be public decls.

const std = @import("std");
test {
  _ = std.posix.windows.mem.indexOfScalar(u8, "hello", 'l');
}

this makes it more confusing to find the public API manually, and impossible for tooling such as autodoc, zls, and future software to know what is an import and what is an intentional part of the api. that's what pub is for.

@pfgithub
Copy link
Contributor

Another example is error sets which are often mistakenly kept private. Just take a look at std.unicode, wrangled with private error sets such as Utf8DecodeError and CalcUtf16LeLenError.

This could be fixed by requiring that "pub" fns only reference types in their arguments and return value that are also public, like rust does. That way if a function is public and it returns Utf8DecodeError!u21, Utf8DecodeError would have to be made public too.

@andrewrk
Copy link
Member

Please do not file a proposal to change the language

@andrewrk andrewrk closed this as not planned Won't fix, can't repro, duplicate, stale Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants