book icon indicating copy to clipboard operation
book copied to clipboard

Chapter 7-4 use rand::Rng is counter-intuitive

Open mathiasbockwoldt opened this issue 3 years ago • 0 comments

  • [x] I have checked the latest main branch to see if this has already been fixed
  • [x] I have searched existing issues and pull requests for duplicates

URL to the section(s) of the book with this problem: https://doc.rust-lang.org/book/ch07-04-bringing-paths-into-scope-with-the-use-keyword.html#using-external-packages https://github.com/rust-lang/book/blob/main/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md

Description of the problem: After learning about how to use modules and getting the syntax and pitfalls right, the example in the paragraph Using External Packages counter everything the reader just learned in the subchapters before. It starts with use rand::Rng; to then actually use rand::thread_rng().... It is very counter-intuitive why we don't write rand::Rng::thread_rng().... Yes, it's a trait we use and yes, the word "trait" is mentioned in the text, but there should be a sentence or two explicitly addressing this perceived problem.

In #2676, pointing out the same (perceived) problem in chapter 2, it was mentioned that the chapter 2 cannot explain everything, and I agree. But here, the example feels like it destroys everything else that is described in chapter 7.

Suggested fix: Please add a sentence or two explaining explicitly why we use rand::Rng and rand::thread_rng(), preferably mentioning and linking the relevant later chapter on traits.

mathiasbockwoldt avatar Oct 27 '22 14:10 mathiasbockwoldt