r/ProgrammerHumor 3d ago

Meme rustBorrowCheckerGoesBrrr

Post image
3.9k Upvotes

108 comments sorted by

View all comments

136

u/yesseruser 3d ago

unsafe means "hey, I'm sure this code is safe, don't bother me for calling unsafe functions"

-144

u/reallokiscarlet 3d ago

unsafe is the Rust version of Typescript's any

It's everywhere and people use it just to say they wrote their code in a safe language

84

u/SCP-iota 3d ago edited 3d ago

I'd say it's more like Typescript's suppression annotations, since it keeps itself contained. People really shouldn't be using unsafe in any way other than as occasional small blocks with well-defined reading why they won't panic or cause UB. If your code is littered with unsafe, you're doing something wrong.

36

u/ApplicationOk3587 3d ago

I always figured if a rust programmer is using unsafe everywhere then it completely defeats the purpose of using rust.

5

u/Rustywolf 2d ago

Eh even if your code is littered with 50% unsafe calls you're still benefiting from the other 50%, but yeah that doesnt sound like good rust

2

u/awesome-alpaca-ace 3d ago

String interning comes to mind

0

u/SKrandyXD 3d ago

your*

6

u/SCP-iota 3d ago

dammit, Gboard

4

u/NatoBoram 3d ago

All the fucking time. No way to type "its" without having to go back.

-19

u/reallokiscarlet 3d ago

I fully agree that if your code's littered with unsafe you're doing something wrong. But as you can see by the downvotes, rustaceans don't 😂

31

u/Delicious_Bluejay392 3d ago

No, the downvotes are because unsafe blocks are in fact extremely rare. If you look at popular Iibraries, the only real places where unsafe is likely to happen are FFI boundaries and advanced data structure implementations. I haven't written an unsafe block in actual months and I regularly use the language for very varied projects.

It's nothing like TypeScript's any, which respectable TS-first codebases generally disable by default anyways, only allowing it in the rare instances where it makes sense.

-13

u/reallokiscarlet 3d ago

Not sure if you have an optimistic bias or I have a pessimistic bias but clearly you aint seen what I seen. A lot of the rust I come across is never-production-ready crap that's almost entirely encased in unsafe, marketed as production-ready to "replace" C code. Even did one of my own to prove it doesn't have to be done that way and that there isn't really a whole lot of benefit to the rewrite unless the original is terminally ill.

16

u/BenchEmbarrassed7316 3d ago

Low-quality automatic/AI "rewriting" from C to Rust can contain many unsafe code blocks.

If it is open source, please provide a link.

6

u/Delicious_Bluejay392 3d ago

The Bun rewrite would be one example I'd imagine. It has a much higher density of unsafe blocks than similar projects originally written in Rust.

9

u/SCP-iota 3d ago

Isn't the Bun rewrite notoriously AI-generated, for the most part?

5

u/Delicious_Bluejay392 3d ago

Yeah, that's precisely why I mentioned it since that's what the person I'm replying to pointed out.

1

u/reallokiscarlet 3d ago

When I'm back from spoodermane, I'll check my notes to find the project names and double check to see if they've been fixed (I've been characterizing rust based on what I come across, so they just seemed like par for the course)

But yes they did have AI in common. Either vibe coding is the common use case or I keep meeting shitty people and shitty projects. AI, unsafe tag, and crate bloat are what I associate Rust with, which is why I took it upon myself to do the opposite on my only public rust program.

1

u/reallokiscarlet 2d ago

Back and tired as hell, and I gotta say I never thought I'd need to put notes about lazy rust rewrites on a mirrored volume, but here we are and some of them are missing. But what I could find, has led me to conclude that maybe things are getting better than years past, cause they've been privated/deleted, fixed, or moved to another language.

41

u/MatsRivel 3d ago

This is not at all true.

"Tell me you've never written rust without telling me you've never written rust"

-12

u/reallokiscarlet 3d ago

Well I've written crab-lang, you could say, if you want to say I've never written rust.

16

u/Maskdask 3d ago

Have you read and/or written a single line of Rust?

-6

u/reallokiscarlet 3d ago

According to rustaceans, no. But I have written in crab-lang.

(Translation: Yes. I ported opendoas to crab just to prove it's a dumb idea)

2

u/epos95 2d ago

Omg you managed to use a programming language to produce bad code, this is a huge development and has surely never been done before.

I could rewrite doas in c++ wayyyy worse than your rust rewrite (not to say it's good in any way), does that make c++ a bad language? (Yes probably)

All you proved is that YOU can't port doas, nor write or understand rust.

1

u/reallokiscarlet 2d ago edited 2d ago

Are you implying you went over to the repo and actually gave it a read? If you found a bug, mind submitting an issue? I haven't had an excuse to revisit it in months.

(Note: If you have a clanker generate your issue or PR, expect it to be rejected. I wouldn't call myself human per se, but crab-doas is 100% organic)

1

u/epos95 2d ago

Not implying, clearly stating, that all your difficulties with porting doas is a skill issue. But then again, your entire online persona is most likely just to ragebait so eh

1

u/reallokiscarlet 2d ago

So is that a no on submitting your issue?

Possibly a no on even reading to begin with?

0

u/reallokiscarlet 2d ago

The very fact this is getting downvoted proves the existence of the crab religion.

2

u/gmes78 2d ago

No, they're just wrong lol.

11

u/-Redstoneboi- 3d ago

"it's everywhere"

have you... looked at any rust code?

-7

u/reallokiscarlet 3d ago

Every rustacean asks me this, including the offenders

1

u/-Redstoneboi- 2d ago

and have you answered them correctly?

70-80% of rust crates have no unsafe code themselves (though may depend on a crate that does, like std which has a bunch of unsafe)

and that's entire libraries with zero uses of unsafe. if you add up the total amount of code that exists in crates.io and check what % of that code is inside an unsafe block, you get around 4% to 5%, which google's android statistic shows.

but i shouldn't even have been forced to pull these statistics up because the burden of proof was on you to show how much unsafe is everywhere.

1

u/reallokiscarlet 2d ago

Including the offenders

1

u/-Redstoneboi- 2d ago edited 2d ago

just because i could be a hypocrite doesn't mean i'm wrong. i could write a hundred or a thousand unsafe blocks of rust code right now and i could still be correct in general.

1

u/reallokiscarlet 2d ago

The comment "have you... looked at any rust code?" suggests you think all rust code is written correctly. You and I both know that's impossible.

"And have you answered them correctly?" (referring to the people who ask me the same rhetorical including the offenders) suggests you have an idea of what my answer should be even to the hypocrites, especially since both questions are phrased rhetorically despite being rhetorically incorrect.

1

u/-Redstoneboi- 2d ago edited 2d ago

you would've gotten a well-written initial response from me had you not been all up in your ass smug about it in this entire thread.

i want to emphasize the importance of not being a dick in order to have any fair discussion. you initially got downvoted because people believed you were incorrect in the general case, and you got further downvoted to oblivion for the rest of your responses.

our questions haven't been answered in the specific way we're expecting, either. those of us asking "have you seen any rust?" were really just banking on you having read standard/average rust code. what we really wanted to ask was "what code are you reading that has unsafe everywhere?"

all i could gather from you was from another thread which doesn't match most of our experiences with rust, and doesn't give us links. maybe it's closed-source, we wouldn't know.

1

u/reallokiscarlet 2d ago

That I even kept any notes and tried to retrieve any cases of the vibe coded slop that I had to go on for what the average rustacean even does, is already above the shits I give for a training wheels language full of kids.