4 ms·
Instead of implementing a workaround for types as namespaces, wouldn't it better to explicitly add namespaces to the language?
by sesm 7mo ago
Instead of implementing a workaround for types as namespaces, wouldn't it better to explicitly add namespaces to the language?
- Arch485 7mo agoIt's not so much a workaround as it is an elegance in design. In Zig, when you @import a file, that file is converted to a struct with comptime fields for all of the public members. Similarly, a "namespace" in Zig is just a nested struct with more fields. Usually it's just another import of something else. N.B.: Coffee hasn't reached my bloodstream yet; accuracy not guaranteed.
- peesem 7mo agofiles aren't converted to structs on import, they _are_ structs (well, their contents are the inside of a struct declaration). also, public members don't become comptime fields? file structs are basically left as-is on import, nearly like you copy&pasted the file contents into a struct declaration
- txdv 7mo agoI think zig is striving for language minimalism, make it minimal as possible then if a feature optimized multiple places use cases benefit