Skip to content

remove the (namespace) type and make every file an empty struct #1047

@andrewrk

Description

@andrewrk

There's not much of a difference between @typeOf(@import("std")) and struct {}. Here are the current differences for example:

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:

zig/std/index.zig

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThis proposal is planned.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions