this post was submitted on 03 Jul 2023
152 points (96.9% liked)

Programmer Humor

18255 readers
698 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
top 12 comments
sorted by: hot top controversial new old
[–] [email protected] 15 points 1 year ago (2 children)
[–] [email protected] 9 points 1 year ago (1 children)

best solution to all rust problems /s

[–] henfredemars 2 points 1 year ago (1 children)

This might be the wrong place for this question, but I have heard criticism that real rust programs contain lots of unsafe code. Is this true?

[–] [email protected] 11 points 1 year ago (1 children)

Define what makes a rust program "real" lol.

Any kind of library that does a lot of low-level stuff (kernel syscalls, custom binary reprs, ffi) will have to use unsafe. But most applications built using these libraries rarely need to use unsafe at all, because the libraries act as safe wrappers to make sure the app developer isn't accidentally violating invariants allowed by the "unsafe" keyword.

[–] [email protected] 4 points 1 year ago

Yeah. For example Lemmy backend is written purely in Rust and doesn’t use unsafe anywhere, but some lower-level library it uses probably does use unsafe for IO code.

[–] [email protected] 2 points 1 year ago

Just use make-static, no unsafety in sight.

[–] [email protected] 13 points 1 year ago (1 children)
[–] [email protected] 5 points 1 year ago (2 children)

I'm definitely missing something here. I'm terrible at rust and c++

[–] [email protected] 18 points 1 year ago (1 children)

The meme refers to the old adage "C lets you shoot yourself on the foot. C++ lets you shoot both feet and gives you a shotgun to do it" - referring to the how C allows you to perform memory-unsafe operations (causing corruption, or worse, security vulnerabilities), and C++'s complexity, potentially obscuring such unsafetyness.

Rust's memory safety tries to save you from doing (un)intentional bad stuff, by giving you compile-time errors. It's also the bane of everyone so used to C/++'s ability to just pass around and modify whatever memory they want.

[–] [email protected] 8 points 1 year ago

I’ve actually never heard that one before. I was specifically referencing this quote by the language’s creator, but I guess that one works too.

[–] [email protected] 5 points 1 year ago (1 children)

What you are missing, of course, is the Rc<Refcell<T>> that you have to stick everywhere to make a nontrivial Rust program. It's like monads in Haskell, parentheses in lisp, verbosity in Java, or warnings in C - they're the magic words you have to incant correctly to make things work in their weird paradigms.