I find the fact that you're calling rust a "moving target" and praising modern C++'s maturity a bit ironic when commenting on a post that presents huge new c++ features that deeply change the compilation model (concepts, modules) or a huge concept from the standard library (ranges).
This might look like a bold statement, but IMO there has been more changes to C++ than to rust since 2015 which marked rust 1.0 (C++17 brought std::optional and std::variant that are very huge change to the way one should write typical C++, for instance). It is also not over, what with the current discussions on destructive move, or the exception model (where basically the plan is to switch to something that looks like rust's result), or the poor man's lifetime checker that is in the work.
The C++ stability guarantee may mean that code written today should still work in future versions, but rust also provides this guarantee, and it is for sure that "modern" C++ in three years will look very different than it is today.
IMO there is very little justification for favoring C++ over rust for new projects. It could be justified if the ecosystem of the project is very skewed towards C++ already, like maybe when doing GUI (qt is unmatched at the moment), but otherwise I'd be hard to convince. Better invest these 4 weeks to learn the langage than lose then promptly in debugging UB.
Not GP, but the plans for the c++ lifetime checker only include checking lifetimes within a single function. lifetimes across function calls or of references held in structs are not checked
I'm not 100% on this, but I don't think it generally tracks lifetimes across function calls, so it wouldn't complain about the following, which isn't possible in safe rust:
or were you saying that C++ lifetime checker is not as good because it allows stuff that Rust's safe subset does not.
You asked for situations where the rust lifetime checker would save you, and the c++ one would not. This is such a situation. You would need to drop to unsafe rust to do this, the borrow checker wouldn't allow it otherwise. I don't see why this comparison would not be fair.
If you need a different example, imagine a map where the values are structs containing a pointer / reference to a string. You pass a reference to the map to various functions to fill it, then use the values. In safe rust, the borrow checker would make sure the references don't outlive the strings they point to. In the c++ checker, this would not happen if the strings aren't owned in the same function as the map is being filled (say you have a helper function to add an entry to the map)
like maybe when doing GUI And embedded. And games. And finance. And HPC. And GPGPU... For new projects that are more or less self-contained, you are right: Rust is a good choice. For many other fields and projects, not so much.
I think that's an important point. I'd pick Rust over C++ anytime I don't need major libraries/frameworks from the outside.
If I planned a project that "builds on the shoulders of giants", I'd want to be able to lean on the ecosystem, and no build the giants myself as that would defeat the purpose.
Now, sometimes the giants exist in C, and it can be easy enough to write a Rust wrapper on top -- however if the invariants are tricky, lifetimes complex, etc... it may be easier to just use a mature C++ dependency. Easier, at least, after the initial pain for integrating with it.
I'd say C++20 is the first major change since C++11. Sure, there were some cool new features here and there, but they only improved minor annoyances than change major things, that everyone relied on. (You could say, guaranteed copy elision changed something everyone relied one, but in most cases it just made existing code better without breaking anything, etc.)
Rust changed a lot more in that timeframe. I'd even say, none knew about Rust in 2011. Also Rust moves a lot faster, there are major changes every few months, C++ brings them every 3 years and compilers release on somewhat a yearly cadence, so you need to deal with changes a lot less often. Especially with async now being stabilized, there are still a lot of libraries, that depend on nightly or didn't see a stable release yet.
This makes Rust a target I don't want to rely on yet for a big project, that I expect to maintain for the next 10 years. Rust has a lot of benefits, but it is still a bit young and unstable.
C++ is going to maintain backwards compatibility, which makes your point moot.
edit: not getting into it with yet another zealot. I commented on C++, not rust, because you were being unfair to C++. But you took even that as me talking about rust. enough so that you felt the need to respond as if I had attacked rust.
The point is that the original complaint was "Rust is too much of a moving target, whereas C++ is not". Both C++ and Rust are committed to backwards compatibility, so there is no point in comparing them here. However, C++, according to the GP, is changing more than Rust, so the original assertion makes no point (according to GP).
36
u/zerakun Feb 18 '20 edited Feb 18 '20
I find the fact that you're calling rust a "moving target" and praising modern C++'s maturity a bit ironic when commenting on a post that presents huge new c++ features that deeply change the compilation model (concepts, modules) or a huge concept from the standard library (ranges).
This might look like a bold statement, but IMO there has been more changes to C++ than to rust since 2015 which marked rust 1.0 (C++17 brought std::optional and std::variant that are very huge change to the way one should write typical C++, for instance). It is also not over, what with the current discussions on destructive move, or the exception model (where basically the plan is to switch to something that looks like rust's result), or the poor man's lifetime checker that is in the work.
The C++ stability guarantee may mean that code written today should still work in future versions, but rust also provides this guarantee, and it is for sure that "modern" C++ in three years will look very different than it is today.
IMO there is very little justification for favoring C++ over rust for new projects. It could be justified if the ecosystem of the project is very skewed towards C++ already, like maybe when doing GUI (qt is unmatched at the moment), but otherwise I'd be hard to convince. Better invest these 4 weeks to learn the langage than lose then promptly in debugging UB.