Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.2k
rename use to usingnamespace #2014
Copy link
Copy link
Closed
Labels
acceptedThis proposal is planned.This proposal is planned.contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.This issue is limited in scope and/or knowledge of Zig internals.proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.This issue suggests language modifications. If it also has the "accepted" label then it is planned.
Milestone
Description
Metadata
Metadata
Assignees
Labels
acceptedThis proposal is planned.This proposal is planned.contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.This issue is limited in scope and/or knowledge of Zig internals.proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.This issue suggests language modifications. If it also has the "accepted" label then it is planned.
After deliberation, I believe that the
usefunctionality 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.zigUsage looks like this:
If
pub usewasn'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.foowe're still in the same position as before: having to look at multipleusedeclarations to find the symbol.So let's not pretend this isn't something Zig supports. Status quo
usesemantics are correct. Here's my proposal to stabilize this aspect of Zig language:usetousingnamespaceusefor zig programmers to use.using namespaceand 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"));.