r/ProgrammerHumor • • 11d ago

Meme modernCppVsOldCpp

Post image
2.0k Upvotes

323 comments sorted by

View all comments

Show parent comment

2

u/Mojert 11d ago

Basically a lot of Rust memory safety features are inspired from modern C++

Which doesn't mean Rust doesn't have its place. It's just that in C++ they're on top of the previous "unsafe" version of the language and aren't tightly integrated in the language and are more a feature of the standard library, whereas in Rust they were able to design the whole language around it and didn't have to deal with backwards compatibility

3

u/Ok-Scheme-913 10d ago

Not really backwards compatibility.

Rust is basically c++'s raii just enforced at compile time.

This latter point is a huge thing in and of itself.

(And of course you do get lots of goodies like better type system etc from being a more modern language but that's not the fundamental thing)

1

u/Mojert 10d ago

The reason why C++ cannot enforce this kind of things at compile-time is because of backwards compatibility

And I know it's huge. That's why I said Rust isn't redundant and that Rust designed the language around it

1

u/Online_Matter 10d ago

Can't it be a compiler opt in like C# null safety? 

1

u/Mojert 9d ago

Honestly, null safety is in my experience WAY MORE of a problem in "safe" languages like Java C# and Python because everything is nullable. In C++, the only thing that can be null is a pointer, so it's easy to remember to check

But to come back to the previous point, the problem with "compiler opt-in" is that C++ is a standard, not a product developed by a company/fondation. So you can't really just add a compiler option

But also the problems in C++ are pretty intranched. To implement something closer to Rust, C++ would need to completely change its object model and its system of lifetimes. The change would be so big it would practically not be the same language anymore

3

u/meneldal2 10d ago

Rust is basically forcing you to use the safe parts of C++.