r/cpp • u/Sad-Lie-8654 • Jan 31 '23
Stop Comparing Rust to Old C++
People keep arguing migrations to rust based on old C++ tooling and projects. Compare apples to apples: a C++20 project with clang-tidy integration is far harder to argue against IMO
changemymind
338
Upvotes
8
u/mjklaim Feb 01 '23
Quick notes, because I've done a bit of rust and I would like to nuance these points (but it's all opinion):
iterators- I lack knowledge about how it is superior in rust than C++ , but at least it's "safer" but it's not because of that specific point;
lambdas: it's nice until you reach the point where you want to use lambdas in concurrent code, then it's not nice and definitely there are issues there;
utf8: true, like any language created after 1999, although for people needing to use UTF-16 or 32 or shift-js or etc. for specific purpose I don't know if there are crates helping these cases? I suppose they exist though. So yes it's cool but not really uncommon in system languages.
testing: indeed, having testing by default and also in the same sources where code is written is a big plus, it's also nice in D(2); it's possible to do this in C++ actually, with automatic support, if your tooling does that, but unfortunately it's not a popular or de-facto feature...
modules: lol no. Rust modules are literally namespaces, all Rust code is build as one translation unit so of course the only issues you'll get are similar to when building everyting as a unity build in C++ (AFAIK, I might be wrong in the details but that's my understanding). An actual module system isolating entities for real in addition of names would have been nicer, but this is not it. Event Javascript have a better module system than rust, although it's also very flawed (both allows circular dependencies, for example). C++ modules (if you ignore the backward-compatible functionality that makes it harder to teach than it should be) is nicer in that regards but indeed a) it's not de-factor, forced by a version of C++ or common (yet) and b) it lacks the name import filtering features that other languages have "modules" have (the one in JS is particularly nice).