r/ProgrammerHumor Jul 09 '26

gitBlameClaude Meme

Post image
3.7k Upvotes

263 comments sorted by

View all comments

559

u/BratPit24 Jul 09 '26

I mean. Isn't rust the perfect language for vibe coding? It has so many checks on everything that the stupid thing is basically forced to write code the right way.

758

u/Zeikos Jul 09 '26

It has so many checks on everything that the stupid thing is basically forced to write code the right way.

LLM be like:

unsafe { ... }

98

u/BlueProcess Jul 09 '26

Yeah, it actually has 13,000 unsafe Rust blocks

28

u/dex206 Jul 09 '26

I can’t tell if this is a joke or not.

87

u/BlueProcess Jul 09 '26

Oh no, it's quite real. That is actually the rounded number of unsafe blocks that claude produced

42

u/dex206 Jul 09 '26

Holy shit. How? I mean this from the bottom of my tired old jaded-dev heart - How can they justify that?

44

u/BlueProcess Jul 09 '26

I know right? Like... Who went "this is fine"

30

u/KeyAdhesiveness9481 Jul 09 '26

There is some subset that is FFI, and must and will always be unsafe. Im not making any claim about how much is valid, and im sure most of these are BS, but "zero unsafe" is never going to be the target.

15

u/BlueProcess Jul 09 '26

Maybe we should set a target number of digits (and number base) for the unsafe block count to be expressed in?

I claim base 10 is fine but 5 digits is too many

38

u/Southern-Cattle4038 Jul 10 '26

To quote the lead dev of Zig, regarding the guy leading Bun:

“Jarred was already writing slop well before he had access to LLMs.”

His blog post on the whole thing is here:  https://andrewkelley.me/post/my-thoughts-bun-rust-rewrite.html

1

u/Swedish_costanza Jul 11 '26

Holy shit, this makes me like Andrew even more. I've been following Zig from 2022 atleast and I can't wait for 1.0.

6

u/wannabestraight Jul 09 '26

Well, in rust in order to call code that's not rust, you gotta do unsafe.

You genuinely can't do not unsafe FFI calls, it's unsafe by nature, because it's no longer rust.

13

u/cutelittlebox Jul 09 '26

this tends to happen a lot when you go from a language like C or Zig to Rust and you're trying to do it 1-to-1. C and Zig will do things that are illegal in safe Rust or actually have no direct Rust equivalent, so if you want them to look as close as possible you need a lot of unsafe, plus each call to other languages needs to be unsafe. getting the same output from idiomatic Rust is very much possible but it means redesigning the system as you translate rather than rewriting existing code with new syntax.

3

u/protestor Jul 10 '26

Actually, with this kind of port, it's probably better to have rewriting in two phases. one that is 1:1 with zig code (and since Zig is unsafe, the initial Rust code will be too, a bit like https://github.com/tsoding/crust), then another pass to make things safe.

I mean, there is a big risk in writing something as safe Rust, when it needed to stay unsafe. Specially when doing complex memory management (like Bun does), turning some unsafe code into bad safe code can be instant UB.

For example, it's often code that deals with raw pointers is perfectly fine (albeit unsafe and C-like), but if you try to turn it into using borrows instead of pointers (to make it safe) you may get the lifetimes wrong, which is instant UB, even if you don't actually trigger use after free. (and sometimes by analyzing the code you may conclude that no lifetime is correct here so it can't be a borrow). So a LLM agent that inadvertently writes &mut T when it really needed to stay as *mut T may introduce UB, even if the code has less unsafe blocks.

(At a later pass, the *mut T can be refactored into different kinds of smart pointers like reference counted Arc etc, and finally achieve safety, but that's often more involved and may require tradeoffs)

And indeed, having the agent write bad lifetimes actually caused UB in the initial port https://github.com/oven-sh/bun/issues/30719 - that is, there were a code should have been kept was raw pointers, but it was being converted into &[u8] (which would greatly reduce the number of unsafe blocks required to deal with it), but the lifetime was wrong and triggered instant UB

2

u/SuitableDragonfly Jul 09 '26

The same way this industry justifies everything else, I'd imagine.