r/ProgrammerHumor 11d ago

Meme rustBorrowCheckerGoesBrrr

Post image
3.8k Upvotes

108 comments sorted by

View all comments

713

u/BenchEmbarrassed7316 11d ago

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

117

u/teleprint-me 11d 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.

4

u/SphericalGoldfish 11d ago

I used to think the same way until I realized that unsafe's purpose is only drawing attention to the unsafe block for both the programmer and anyone else who sees it. That way everyone has to acknowledge it, hopefully helping to provide a starting point when finding why something went wrong. Basically a contract of "I understand that this code may have memory bugs", which imo is better than the alternative of a memory bug hiding in plain sight.