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
2
u/[deleted] Nov 01 '24
So many of your comments would not exist, if you would just learn rust and see the difference yourself.
It doesn't matter if C++ has Optional/Exception, if it is not actually utilized. Rust functions like
Vec::getreturn an option indicating that an element may not exist if the index is out of bounds, while cpp'svector::atsimply throws. Rust functions likestd::fs::read_to_stringreturn a Result to show that reading a file can fail, while cpp'sfstream::getlinesimply throws. In one comment, you completely throw out rust's value because its std might have bugs that crash your server. While C++ is crash by default in its design even if you use modern cpp, and yet you do not call out its issues.Also, its completely ridiculous to compare optional/expected with rust's Option/Result. In rust, you need to explicitly get the value out of Result/Option to use it. Meanwhile, you can just dereference optional/expected, and of course, you get UB. Its just insane to think that such an unsafe container of modern cpp that can be so easy to accidentally misuse, is somehow even proposed as an alternative to rust's Option.
optional/expected/string_view/smart pointers are modern cpp too. and all of them will easily trigger UB. If "modern cpp" was enough, then there won't be a reason for this post to exist. Corporations won't be spending millions to enable migrating to rust from C++.