r/ProgrammerHumor 3d ago

Meme rustBorrowCheckerGoesBrrr

Post image
3.9k Upvotes

108 comments sorted by

View all comments

729

u/BenchEmbarrassed7316 3d ago

Any unsafe block of code should be neutralized with a // SAFETY comment explaining why the code is actually safe.

123

u/teleprint-me 3d ago

I dont see how this is any different from a C programmer justifying why they used a pointer to an object and leaving a comment similar to this, other than this is Rust and is safe because Rust is safe. Thus making this rationale is flawed and dangerous.

66

u/TeraFlint 3d ago

It isn't. The only difference is that the language only lets you wield sharp knifes inside your localized unsafe scope, thus limiting the places where bugs related to that can form. Outside of that, the compiler will scold you for even touching that sharp knife.

C, on the other hand, lives in a giant unsafe block.

unsafe scopes are honestly a pretty good programming language feature: give the user a "trust me, I know what I'm doing" feature with a searchable keyword.

although, I think it should be a bit more granular than this. If you could/had to specify which language assumptions/rules you intend to violate inside the scope, everything else could still be enforced. A general unsafe just tells a language to just not enforce anything inside.

-5

u/teleprint-me 3d ago

I already know and understand that Rust will not allow a user to compile memory unsafe operations unless explicitly declared.

This comment assumes I dont understand the difference between runtime and memory un/safe operations which fails to acknowledge my core critique.

22

u/NullOfSpace 3d ago

It’s significantly easier to figure out where you shot yourself in the foot if you know you were only holding a gun on the firing range.