The main issue with this post is that all the work mentioned about how much better Rust is is actually being handled in the globwalk crate. You could write the same library in C++.
And then the actual problem here seems to just be not that C++ is doing anything wrong here but that it's hard to find documentation on std::ifstream.
And finally, of course, ranges exist in C++ as well and all that amazing transformation to a parallel version can be done the same way in C++.
uncertainty around the std::ifstream constructor's behaviour with respect to errors. Arguably one of the most popular C++ references stays silent on error cases. In Rust the signature of std::fs::File::open alone is clear enough w.r.t. error reporting.
The Rust type system is rich enough that necessary constraints for thread-safety can be expressed. The "straight forward" attempt of paralellization in Rust using par_iter().for_each(...) will make the compiler basically complain about the fact that the closure object being passed to for_each wouldn't be thread-safe as it tries to "mutably borrow" the wordcountsHashMap. This is super cool. C++ doesn't help you avoid data races at all. It just accepts your code under the assumption that you know what you're doing.
While I don't find the 1st point to be particularly impressive, I have to agree with the expressive power of Rust's type system with respect to (1) lifetime constraints and (2) mutual exclusion of "write access" which are the foundation for the memory and thread-safety guarantees Rust is able to make. I mean, there is just no comparison with C++ even if you factor in the efforts of Microsoft's "lifetime safety checker" which doesn't cover thread-safety and doesn't guarantee 100% lifetime safety.
This thread of conversation itself is an excellent object lesson on why having the shape of possible errors on the function signature is so much better than having them buried in documentation somewhere, even when that documentation is good.
Meson wraps (I use Meson). It lists around 144 packages. I have used sdl2, catch2, json, libpng, onqtam-doctest and others. It works pretty well given that this terrain has been sooo bad for C++ in the past. However, there is a lot to do to reach Cargo-level. All my hopes in dds.
A library is just code that other code uses. It comes in various flavors such as static or dynamic, but either way it's another dependency that can and should be managed automatically.
I assume you're referring to how C++ commonly makes you install external libraries to the system. Because if so that's one of the worst things about the C++ ecosystem IMO. A virtual environment completely separate from system libraries, fully managed by a first party builder+package manager, is ideal.
It's not when you have a package manager built into the language. The fact that a crate exists and the fact that it's trivial to import into your project shows how important package managers are to modern languages.
You're going to have to write the code anyways which will increase your compilation time. And why wouldn't you want to depend on yet another random author? Do you seriously enjoy reinventing the wheel or something?
45
u/readams Oct 18 '20
The main issue with this post is that all the work mentioned about how much better Rust is is actually being handled in the globwalk crate. You could write the same library in C++.
And then the actual problem here seems to just be not that C++ is doing anything wrong here but that it's hard to find documentation on std::ifstream.
And finally, of course, ranges exist in C++ as well and all that amazing transformation to a parallel version can be done the same way in C++.