Data point about the new module system learnability and musings about language stability

To me files are a stronger unit and more fundamental than a module, and definitely were when I was learning modules (and failing to get them, and being extremely frustrated that they fail when I use multiple files, and the book only shows inline case that is too easy and has no practical use for me).

As I've explained in the issue, the current chapter doesn't explicitly state the crucial difference between how modules are split in Rust and most other languages:

If you take an inline module and split it into files (- lines), in Rust it's:

+// Outside module
+pub mod instrument {
-    // Inside module
-    pub fn clarinet() {
-        
-    }
+}

but in C++/PHP/Go, if mod was equivalent to namespace or package, it'd be:

+// Outside module
-pub mod instrument {
-    // Inside module
-    pub fn clarinet() {
-        
-    }
-}

mod m; also maps more or less to JS const m = require("m.rs"), but that construct doesn't have an inline analog.

To me this was problematic, because mod is like namespace in inline examples, but the inline examples don't apply to multi-file case. When files are involved suddenly the analogy is wrong, and it's not 1:1 mapped to namespace, but becomes a different syntactical construct with the namespace being outside of the file, rather than inside.

2 Likes