4 ms·
The confusion around Rust's modules reminds me of the different ways that people learn how to use car indicators. Some people learn that you push the stalk up
by jeffparsons 6y ago
The confusion around Rust's modules reminds me of the different ways that people learn how to use car indicators.
Some people learn that you push the stalk up to indicate your intent to turn left, or down to turn right. And then they might eventually learn that in a European car, you push the stalk down to turn left, and up to turn right. And then of course some of these people get confused when switching between different cars. Yes, I've seen plenty of people on the road who indicate one direction and then turn another. It's... kind of frightening.
The other way of learning to use car indicators is much simpler: push the stalk in the direction that you would turn the wheel. Of course this still leaves the possibility that some people will push the wrong stalk, and briefly activate their windshield wipers. But it's a much easier mistake to _notice_, and the consequences are minor.
Back to Rust's modules. I keep seeing articles trying to offer a simple or clear explanation of how they work, that end up unnecessarily complicated in a way that feels a lot like the "up/down" model of car indicators. The explanation that makes the basics of Rust modules clear to me is this:
- Child modules must always be _declared_ in the parent module, or they don't exist.
- The content of child modules may be _defined_ either inline in the parent as `mod child { ... }`, or in a file with a relative path of './child.rs' or './child/mod.rs'.
Did I miss anything important?
Without this basic explanation up-front, I have no idea what to do with the stream of information I'm reading in a lengthy article on the topic -- I've been given no scaffolding onto which to bolt all the details and examples. So this is the "bottom line" that I would like to see "up front" in descriptions of Rust's modules.
Other misunderstandings, e.g., around item visibility, are explained really well by the compiler if you get them mixed up, so I'm not sure how much value there is in mixing them in to articles about how modules are _structured_ before those two basic facts are presented.
- Twisol 6y ago> Some people learn that you push the stalk up to indicate your intent to turn left, or down to turn right. I was very confused for a good moment, because the turn signal in my car (which I drive in California) is on the left side of the steering wheel (itself on the left side of the car). I didn't realize the stalk might be on the right side of the wheel in other driver's-side-left cars until you said "some people will push the wrong stalk". The "push the stalk in the direction that you would turn the wheel" method is intuitive to me.