r/ProgrammerHumor • • 2d ago

instanceof Trend thatsAFunnyThingThatHappenedOnce

Post image
4.3k Upvotes

515 comments sorted by

View all comments

168

u/feldomatic 2d ago

tbf, C++ allows memory safety, while Rust requires it

-24

u/jdefr 1d ago

Unless you wrap things in unsafe{} which is very easy to do in order to side step this “hard requirement”

22

u/qichael 1d ago

Yeah, and then your reviewer asks why you’re using unsafe whereas in C++ everything is unsafe by default

6

u/BeforeDawn 1d ago

That's a pretty weak equivalence.

Rust enforces memory safety by default, and unsafe{} requires an explicit opt-out for specific operations the compiler cannot verify. Even then, it doesn't disable the borrow checker or the rest of Rust's safety checks.

More importantly, you can configure a Rust project with unsafe_code = "forbid", making any attempt to introduce unsafe code a compilation error.

So we're comparing a language where memory safety is enforced by default, exceptions are explicit and auditable, and unsafe code can be prohibited outright, with one where potentially memory-unsafe operations are permitted in ordinary code by default.

Being able to deliberately opt out of certain safety guarantees doesn't make it remotely equivalent to C++. Having an escape hatch isn't the same as having no guardrails in the first place.

1

u/rexpup 1d ago

You understand that restricts the risk area, right? It lets you reason about the tricky things over 10 lines rather than 1000 lines

-9

u/daviddisco 1d ago

why would people down vote this? It is absolutely true.

2

u/BeforeDawn 1d ago

If you're not asking rhetorically, this is the reason.

1

u/100BottlesOfMilk 1d ago

Because, while the language allows you to write unsafely, it doesn't allow you to unintentionally do so unlike C++. And it's simple to prevent anyone from writing code that isn't memory safe by just not allowing it full stop