←back to thread

In Defense of C++

(dayvster.com)
185 points todsacerdoti | 2 comments | | HN request time: 0.396s | source
Show context
jasperry ◴[] No.45268190[source]
The author argues that if rewriting a C++ codebase in Rust makes it more memory-safe, that's not because Rust is memory-safe. What?
replies(4): >>45268492 #>>45268504 #>>45268572 #>>45268997 #
bluGill ◴[] No.45268504[source]
I would argue that rewrite in C++ will make it a lot better. Rust does have some nice memory safe features that are nice enough that you should question why someone did a rewrite and stuck with C++, but that C++ rewrite would fix a lot.
replies(2): >>45268618 #>>45268879 #
1. pie_flavor ◴[] No.45268618[source]
Fresh codebases have more bugs than mature codebases. Rewriting does not fix bugs; it is a fresh codebase that may have different bugs but extremely rarely fewer bugs than the codebase most of the bugs have been patched out of. Rewriting it in Rust reduces the bugs because Rust inherently prevents large categories of bugs. Rewriting it in C++ has no magical properties that initially writing it in C++ doesn't, especially if you weren't around for the writing of the original. Maybe if there is some especially persnickety known bug that would require a major rearchitecture and you plan to implement this architecture this time around, but that is not the modal bug, and the article is especially talking about memory safety bugs which are a totally separate kind of thing from that.
replies(1): >>45274098 #
2. Attrecomet ◴[] No.45274098[source]
A rewrite of your C++0x codebase that's grown from 2009 until now will most definitely fix loads of memory bugs, since C++ has very much evolved in this area since then. The added value of the borrow checker compared with modern C++ is a lot less than compared with legacy C++.

That said, I still think it's a rather weak argument, even if we do accept that the rewrite will do most of the bug removal, since we aren't stupid and move to smart pointers, more stl usage and for each loops. "Most" is not "all".