Remix.run Logo
carlmr 7 months ago

>the one easier to use is going to get wider spread / adoption

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.

UncleMeat 7 months ago | parent | next [-]

Yep. I've been developing in C++ professionally for a decade and I still have to look up "what's the safe way of making a string literal available in a header file" when it comes up.

MrLeap 7 months ago | parent [-]

C++ was the first programming language I ever learned, but I've only written a few hundred lines of it over the last 2 decades. Never professionally.

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.

ranger_danger 7 months ago | parent [-]

Not OP but I think it depends on your definition of 'string'. For example there are some very grumpy devs who believe that C has no strings, and that "const char*" cannot ever be considered a string, and that anyone else who claims so is wrong.

tialaramex 7 months ago | parent [-]

This is made more confusing by C++ basically insisting that your "basic" built-in string type has to have the small string optimisation. The guts of std::string in any of the three popular stdlib implementations are... pretty complicated. In contrast Rust's String is literally just Vec<u8> [a growable array of bytes] plus a promise that these bytes are always a UTF-8 encoded string.

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.

saagarjha 7 months ago | parent [-]

C++ doesn't require any of this. Everyone implements it this way because it is cheap and improves performance. And people don't take (const) char * they take const std::string &.

grayhatter 7 months ago | parent | prev | next [-]

I'm used to writing C, and think pointers are easy to understand. I wouldn't call rust 'hard' to learn, but it is without a doubt painful. You also aren't doing manual memory management in rust either... I'd assume the sentiment comes from the irrelevant hoops rust makes you jump through to just compile something simple.

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.

ipdashc 7 months ago | parent [-]

> 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

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.

grayhatter 7 months ago | parent [-]

I deleted all IDE features (other than good highlighting) and I'm never going back! I kept adding more and more IDE features, and my subjective enjoyment and happiness writing code kept decreasing. I deleted them, and I love writing code again!

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.

tialaramex 7 months ago | parent [-]

Unlike your parent, I don't use an IDE at all, I write Rust in just a plain vim, no language server, I don't even bother with syntax highlighting.

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.

grayhatter 7 months ago | parent [-]

The very first time I used rust for a work project, I tried to implement a tree... well actually I tried to implement a linked list first, later hoping to expand it into a graph.

The distinction that's aggravating me is the compiler refuses to compile code that I know is correct, but it's not smart enough to prove it, so it just gives me the finger instead.

chucke1992 7 months ago | parent | prev [-]

C++ has much more bigger inertia. It is like the "default" for all the areas where it is being used. So when learning a language people would rather go to C++ first and then to Rust, if they are really planning to work in corresponding area (game dev etc.). Or even go to C.

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.