Skip to content

RFC: Improve the module system #11745

Closed
Closed
@kud1ing

Description

@kud1ing

I am not sure what the chances are, but if it could be improved, it should be before 1.0.
Rust's module system has a steep learning/doing curve. I think there are two reasons for this:

  1. Importing functionality and importing namespace are two steps: mod and use. This leads to the shadowing rules, that have weird consequences: you need to import a path via use which is not even defined at this point in time, because use needs to before mod. I find this not only unfamiliar but also counterintuitive.
  2. The compiled file becomes a crate. In most languages you can iteratively compose a project of files/modules and use/compile those individually. Since use statements are relative to the crate, the meaning changes depending on which file you currently compile. The consequence is that it makes it more difficult than necessary to first write file a.rs, then b.rs (uses a.rs), and then c.rs (uses b.rs) and make them compile individually. Even in Haskell that is easy. In Rust you either have to go back and forth and adjust the use-staments or only put the mod-statements in a dedicated top-level crate (lib.rs or main.rs) which defies encapsulation.

This could be an issue that is fixable with more/better documentation. However, when you need a lot of words/actions to describe/do something in one system which does not need that care in another system, that could be an indication that there is some accidental complexity. I think this complexity is accidental since i am not yet aware of which gains are compensating for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions