An idea to address path confusion


The fact that use declarations work with absolute paths while other items do not is confusing. To make matters worse, the top-level namespace contains all of the external crates, but also the contents of the current crate. And finally, when you’re working at the top level, the absolute/relative distinction doesn’t matter, which means that you can have the wrong mental model and only find it when trying to expand out into submodules.

The problem statement suggests a solution.

The top-level namespace contains both crates and contents of the current crate. To address the issue, we can remove contents of the current crate from the top-level namespace, so that it only contains crates. If the current crate is named “hello”, two names are added to the top-level namespace, “hello” and “crate”. Using “hello” allows you to copy and paste the code to other crates, using “crate” allows you to rename the crate without other changes.

Use paths are always rooted by crate name. Therefore, use paths are always manifestly absolute, and you can’t form the wrong mental model while only working at the top level. Path confusion is addressed by breaking relative paths to not-working even at the top level, because they won’t work in submodules.


closed #2

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.