Zig: Proposal: Remove the usingnamespace keyword in favor of re-using existing syntax

Created on 22 Nov 2020  路  1Comment  路  Source: ziglang/zig

This is just a suggestion, but I feel like the usingnamespace keyword adds unnecessary complexity to the language. I really like how Zig uses variables like namespaces, and usingnamespace really breaks that nice pattern.

I feel that the statement _ = @import("std"); is far more intuitive and consistent with the rest of the language than usingnamespace @import("std");

Already in the language, the underscore can be used to mean "I don't want to assign this to a variable / constant", and it would make sense that if you don't want to assign the value of @import() to a constant, it would imply that you want to use the functions / variables from the imported file directly. It also makes sense visually, because the underscore is kind of like a blank character.

I am aware that this is a little nitpicky, but I thought I'd throw it out there as I think that it is important that Zig be as simple as possible.

proposal

Most helpful comment

I would find it odd if _ = @import("foo.zig"); imported the decls where _ in all other contexts means to throw away/ignore the result and this change seems to make _ = ... mean differently depending on where it's used.

example:

struct {
  _ = @import("thing.zig"); // imports all decls
  fn foo() void {
    _ = @import("stuff.zig"); // what should happen here?
  }
}

>All comments

I would find it odd if _ = @import("foo.zig"); imported the decls where _ in all other contexts means to throw away/ignore the result and this change seems to make _ = ... mean differently depending on where it's used.

example:

struct {
  _ = @import("thing.zig"); // imports all decls
  fn foo() void {
    _ = @import("stuff.zig"); // what should happen here?
  }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

bheads picture bheads  路  3Comments

DavidYKay picture DavidYKay  路  3Comments

andrewrk picture andrewrk  路  3Comments

zimmi picture zimmi  路  3Comments

bronze1man picture bronze1man  路  3Comments