cognitive-engineering-lab / rust-book

The Rust Programming Language: Experimental Edition
https://rust-book.cs.brown.edu
Other
503 stars 82 forks source link

ch04.5 a inappropriate description about GC #185

Open CybCom opened 2 months ago

CybCom commented 2 months ago

The description about the second drawback of GC here is not very appropriate. It asked "what are the contents of the document d" might be mutated in the python example, but this mutation is not a direct consequent of GC, but a result of lacking permission checkers, and will also happens in the languages that does not even have a GC, like C or C++.

willcrichton commented 6 days ago

It's a direct consequence of unrestricted aliasing, which happens in nearly every GC'd language. I don't talk about "unrestricted aliasing" because that is less familiar to the general programmer than "garbage collector". I think if someone arrives at your level of understanding to understand the nuances, I'm happy with that, but it's not essential in that part of the text.

CybCom commented 6 days ago

Thanks for your explanation! I've just re-read this paragraph. I suggest to address explicitly that "both GC and Ownership could avoid UB, but why we chose Ownership here is because just using a GC is still unpredictable (still permits unrestricted aliasing)".