-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
rename use
to usingnamespace
#2014
Comments
Am I mistaken, or is the alternative to this: const c = @import("c.zig");
test "example" {
c.c.printf("hi\n");
} ...this? const c = @import("c.zig").c;
test "example: {
c.printf("hi\n");
} I recognize it's a subtlety which could slow down and confuse newcomers, not to mention it's a slight annoyance. But does this one gotcha justify a new keyword and language feature? If so, are there alternative proposals which are scoped purely to the problem described (providing cleaner, more obvious callsite usage)? My beef with (For the record, I still think the keyword rename itself is a positive change.) |
@raulgrell There's no longer a |
See #2014 `use` syntax is still accepted for now. `zig fmt` automatically updates code. After a release cycle the old syntax will be removed.
You are correct - that is the alternative.
I agree with you if that was the only issue, I think it would not necessitate this feature. The standard library has some other examples of usage where I felt it was a proper use of the feature, most notably the "bits.zig" files (and where those are imported). If you are willing to create a proof of concept of how the std lib would be reorganized without the |
After deliberation, I believe that the
use
functionality of Zig will stay. Here is my reasoning:This use case is valid (from https://github.com/andrewrk/tetris/blob/8c22d4956348d3ce64cdbeccc4fa8204d94a2eaa/src/c.zig):
c.zig
Usage looks like this:
If
pub use
wasn't possible, at the callsite it would look like this:Indeed, every time a file wanted to expose its own dependency to its dependents, this would happen.
If this feature existed without "splatting" into the same file, it would still be possible to obtain the previous "use" behavior. Coders could introduce an indirect file which does all the splatting, and then in the file that imports it,
const x = @import("indirect.zig");
, and then when doingx.foo
we're still in the same position as before: having to look at multipleuse
declarations to find the symbol.So let's not pretend this isn't something Zig supports. Status quo
use
semantics are correct. Here's my proposal to stabilize this aspect of Zig language:use
tousingnamespace
use
for zig programmers to use.using namespace
and it does exactly the same thing.use
(See add docs for usingnamespace #1589) in part to discourage its use because I was not sure if it would get deleted or not. This proposal would make the feature considered relatively stable. So document it, make it clear that it should generally be avoided, and explain what are good situations for it.One more unrelated argument for keeping it. Zig intends to beat C at its own game. Code can be translated pretty directly from C to Zig when you e.g.
usingnamespace @cImport(@cInclude("stdlib.h"));
.The text was updated successfully, but these errors were encountered: