-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
acceptedThis proposal is planned.This proposal is planned.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
Description
There's not much of a difference between @typeOf(@import("std")) and struct {}. Here are the current differences for example:
- you cannot instantiate a namespace
- namespaces cannot have fields
- reflection reveals the top level declarations of structs but not namespaces (issue Why zig can not list pub variables name and type in namespace type at compiler time? #1043)
- structs cannot have tests inside them (but why not?)
- structs cannot have
useinside them (but why not?)
Making a file be an empty struct instead of a namespace would accomplish the following things:
- solve the "but why not?" questions above
- this is especially attractive for the reflection use case since one could eliminate redundant code for namespaces and structs
- remove a type from the language, thus making the language simpler and smaller
- if we allowed fields at top level, then it would solve the redundant import problem:
Lines 3 to 10 in 96164ce
| pub const BufMap = @import("buf_map.zig").BufMap; | |
| pub const BufSet = @import("buf_set.zig").BufSet; | |
| pub const Buffer = @import("buffer.zig").Buffer; | |
| pub const BufferOutStream = @import("buffer.zig").BufferOutStream; | |
| pub const HashMap = @import("hash_map.zig").HashMap; | |
| pub const LinkedList = @import("linked_list.zig").LinkedList; | |
| pub const IntrusiveLinkedList = @import("linked_list.zig").IntrusiveLinkedList; | |
| pub const SegmentedList = @import("segmented_list.zig").SegmentedList; |
Thanks @tgschultz for coming up with this idea.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
acceptedThis proposal is planned.This proposal is planned.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.