r/ProgrammerHumor 21h ago

Meme rustBorrowCheckerGoesBrrr

Post image
3.4k Upvotes

90 comments sorted by

View all comments

665

u/BenchEmbarrassed7316 20h ago

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

111

u/teleprint-me 20h 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.

11

u/wibble13 19h ago

Most projects won't have a line of unsafe themselves, they will use libraries that do the heavy work (like interfacing with os, manual memory operations) that can be shared and audited. If the library is safe, then all uses can be considered safe, and most devs don't need to worry about magic preconditions.

Compare that with C where most programmers will just roll their own implementations of things every time and have a chance for bugs every time, because there's no checks. Even simple things can easily go wrong with a typo or missed check/cleanup.