by carlmr · 2y ago · 0 comments
Between Rust and C++, this is Rust. In C++ you need to a lot more memory safety verification in your head, there are thousands of footguns that you need to be aware of at all times, the template metaprogramming facilities are really hard to grok with their weird syntax.
Rust is strict, but for the kinds of applications that you would replace C++ in this makes it a lot easier to learn.
I think the sentiment that Rust is hard comes from people that come from managed languages (Python/Java/C#) that aren't used to manual memory management. From that perspective Rust is indeed hard.
Can you elaborate on the dangers of doing this incorrectly? What kinds of dangers are there in making a string literal available to a header file.
And by C++ taking a long time to get the natural string slice type, which it calls `std::string_view`. This type is what you almost always want in APIs that aren't responsible for growing and changing strings - for the names of things, labels, parsing and so on. Because this type was not in C++ 98 or C++ 11 or even C++ 14 people would use `std::string` instead even though they did not need to modify, let alone grow, the text or, since they don't want the overhead of `std::string`, they would use `char *`
It was correct for C++ to seek to do better than C here, but while what they delivered was a lot more powerful it's not clearly better and I think has contributed to widespread misunderstanding.
You don't need to be aware of 1000s of foot guns for every block of non rust code. But you do have to remember dozens of pedantic rules, or stdlib wrappers just to trick rust into allowing you to compile your simple/demo code.
Have you tried using rust-analyzer? I'm usually a bit of an IDE skeptic, but Rust is one of those languages where tight integration with the IDE really helps IMO. It's night and day, I honestly wouldn't want to write Rust without rust-analyzer, but with it it's quite pleasant.
I think the fact that the language is aggravating without complex and tight IDE integration is one of the best indictments of the language there is. Java is another language that's intolerable without impossibly complex IDE support. The more rust matures the more it feels like that.
Still, I'd say that actually the distinction that's aggravating you is almost entirely that Rust won't compile a lot of code that's nonsense, whereas in C++ that code compiles - it's still nonsense, but it compiled anyway. I think that's just plainly worse.
Rust will probably replace C++ in some areas where it is a legacy app (or part of the app) that is not changed frequently anymore.