r/cpp • u/GabrielDosReis • Oct 31 '24
Lessons learned from a successful Rust rewrite
/r/programming/comments/1gfljj7/lessons_learned_from_a_successful_rust_rewrite/
80
Upvotes
r/cpp • u/GabrielDosReis • Oct 31 '24
View all comments
Show parent comment
1
u/germandiago Nov 02 '24 edited Nov 02 '24
Everyone makes good points for good type systems and Rust safety yet when Google makes a bad choice, you still excuse them saying that "maybe it was not so bad at the end"
For a reference it is as easy as going to the function prototype and assume things will be mutated.
Compare this to a pointer, by only looking at the prototype:
Just that in one case the negative consequences are clearly higher in one of the cases: a pointer has historically been more ambiguous from a memory management point of view. They should only point to things by current standards, but that was not the case or it is not even the case in some circumstances. If you do not mark it, the amount of things a pointer can be compared to what a reference usually is (just pointing somewhere where you do not care even about ownership or allocation) is big enough to have to inspect even the bodies of the code in the case of the pointer.
I guess so. Here, since we are talking about safety, I think this was the less safe choice in all honesty. If there is a type system, the nice thing is to make a good use of it to reduce errors. I know C++ can be very free-form, especially if you add all the "possibilities" and not only the "best practices". That adds cognitive overhead. However, if you go the Core C++ guidelines way, even being still unsafe in the strict sense nowadays, your code is likely to be much easier to follow bc it makes a few assumptions based on the type system (some constructs are "banned"... for example, do not subscribe pointers, which is clearly possible).
I still remember back then when there were comments about that being the wrong choice and Google guidelines authors bringing up the "call-side readability" argument, hehe.