I like to quickly at a glance be able to distinguish between "this is a member access on an object" and "this is referencing something in a module".

I like that the compiler can distinguish those two things too, so that I can refer to things within modules even if I happen to also have a local variable with the same name. Go sometimes annoys me because I need to rename a module or a variable just because the syntax doesn't distinguish between the two things.

> distinguish between "this is a member access on an object" and "this is referencing something in a module".

zig: what's the difference?

There is an overlap between module and class namespacing through static members and functions. Zig sees this and says "let's only have the latter" (on structs), which means among other things that in Zig a file is a structure. Most other languages says "let's have both".

In C3 it goes the other way despite having methods, and says "let's not allow static variables or methods".

This also goes hand in hand in the language approaches between open/close. Zig is very strongly "closed" and C3 is very much "open" (adding methods to types anywhere, appending to modules anywhere etc)

It's an interesting contrast that leads to very different code layouts.

Surely Zig differentiates between, say, a function in a module, and a member on an object? Or are "modules" literally just instances of classes or something?

all structs are namespaces (there no classes). namespaces may contain declarations (consts and functions) or fields ("fields" are slightly different for unions or certain builtins like arrays and slices)

unions and enums also create namespaces. any @import creates a namespace that is a struct.

If a function's first argument is the type of the function's namespace or a pointer to the type of the namespace, you may (and by convention are encouraged to) use dot dereferencing (like python firso parameter self) as a lexical sugar to call the function with the "implicitly rearranged" first parameter ("oop style caling, but not really oop")

modules are somewhat different, in zig these are collections of code you can map to a non-filepath import string using the command line or build tool (in particular you may map something out of code root path), but these too ultimately become a namespace struct

And you're saying that a modules are instances of structs? Meaning functions in modules are non-static methods?

modules are struct namespaces, so they create a compile time type.

modules (might not mean the same as module in any other given lang) ⊂ imports ⊂ structs ⊂ namespaces ⊂ types

Right, that's what I thought. So object member lookup and module/namespace lookup are not the same thing

Depends. Your module can have top level member fields or declarations. (By convention these modules would be capitalized) and in that case it would be instantiated as a struct (no objects in zig)

MyModule.zig

   somefield: u32,

   fn get(self: @This()) u32 {
      return this.somefield;
   }
main.zig

   const Module = @import("MyModule"); // note there are build parameters necessary to make this a module

   fn main() void {
     var x: Module = .{.somefield = 42 };

     _ = x.get() // => 42

     ...

A module is an import external to your project. Whether or not the import has top level fields or declarations, the mechanism is the same for structs, imports, and modules. For all imports (including modules) you should imagine an implicit `struct{...}` expression surrounding the code in your file.

I don't understand why you're repeating this. The module is a struct, not an object. That means that in Zig, module lookup and object member lookup are different things. A module is not an object, it is a struct, so looking something up in a module is not looking up a member in an object.

Please enlighten me, what are objects in zig? As far as i know this is not a defined concept in the language, so I'm assuming you think that structs are objects because struct namespace functions can be called with a syntactic sugar that makes it look like an object in a language that has them.

Do you mean object like object file (to be linked)? Those don't have member functions as far as I know.

Why would I think that structs are objects?

I'm using "object" as it is commonly used; essentially a value. In e.g Java or C or C++, the struct/class is a type, and an instance of the struct/class is an object.

Accessing an object's members is a different operation from looking up a symbol in a namespace. Even in Zig.

No, they are the same.