3 ms·
> produced idiomatic rust I keep seeing this. What is "un-idiomatic" rust?
by irishcoffee 3mo ago
> produced idiomatic rust
I keep seeing this. What is "un-idiomatic" rust?
- vessenes 3mo agoPresumably lots of stuff wrapped in 'unsafe'. I'm not a rust guy or a rust fan, and the last time I wrote something with Rust was like 7 years ago, but to my memory, because of how Rust manages mutability there are many access patterns that are Rust-specific; idiomatic Rust is going to use this patterns but they would be unlikely to show up in a language with a different type system / borrow checker / etc. etc.
- irishcoffee 3mo agoSo "unidiomatic" rust means, 'don't use these parts of the language even though they're first-class citizens?' How odd. Lot of mental gymnastics going on there.
- tribaal 3mo agoIt's mostly the same in any general purpose programming language though, parts of the language features are meant (or became seens as) tools to be used in very narrow cases, which people less familiar with the language tend to "overuse". Eg. goto/jump, bare "except" statements in python, etc... In Rust, unsafe has its uses and is a first class language feature, but it certainly isn't idiomatic to use it to mimic access patterns from other languages (unless absolutely necessary).
- flohofwoe 3mo agoThe Bun author himself writes that the port is not idiomatic Rust: Do the rewrite that looks like we transpiled our Zig code to Rust. We can gradually refactor it to reduce unsafe usage and look more like idiomatic Rust after Bun v1.4 ships. (from: https://bun.com/blog/bun-in-rust https://bun.com/blog/bun-in-rust) The original version of Bun was already a line-by-line (manual) port of esbuild from Go to Zig (also mentioned in this post), so the Zig code already wasn't "Zig-idiomatic" and apparently riddled with problems. That doesn't inspire much confidence in the LLM-translated Rust version tbh.
- skeledrew 3mo ago> That doesn't inspire much confidence in the LLM-translated Rust version tbh. And yet Claude Code, which is the primary consumer, continues to chug away without any issue (that I, as a fairly heavy user, have encountered).
- ModernMech 3mo agoIt means "don't misuse parts of the language in ways that circumvent best practices" one of which is "keep unsafe regions as small and few as possible" not "never use unsafe"
- vessenes 3mo agoMeh. The (a major?) goal of Rust is this sort of type safety flowing down to memory bugs. Not every possible access pattern was known at the beginning, and generally they developed a philosophy of keeping the "unsafe" memory access patterns extremely bounded and heavily inspected. I think that's a fair and admirable goal.
- williamdclt 3mo ago> "unidiomatic" rust means, 'don't use these parts of the language even though they're first-class citizens?' that is indeed a roughly accurate definition of what "unidiomatic" means
- TazeTSchnitzel 3mo agoRust contains the ability to do everything that C can, if you use `unsafe`. And a file-by-file rewrite in Rust from another language usually involves keeping the ABI and API between files very C-like (and unsafe). In practice this means that the result of a first pass this way has all the memory safety of C code, but with worse readability because Rust makes unsafe things less ergonomic. To actually get the safety benefits of Rust in a real way you have to rework those files to not treat eachother as C code. This is the interesting and the difficult part of a rewrite in Rust, and one that an unsupervised LLM rewrite is probably not even going to attempt. I don't think this latter stage has actually happened with Bun's codebase. The result of the Rust rewrite in Bun's case is actually less safe than the Zig it is replacing, especially because (I am told) a lot of the new Rust code is unsound (introducing UB).
- skeledrew 3mo ago> one that an unsupervised LLM rewrite is probably not even going to attempt. Why not? A complete test suite exists, so it just boils down to "reimplement this code to reduce the number of 'unsafe' references, while keeping the tests passing" (the last part isn't even needed since Claude loves to run tests and linters anyway).
- TazeTSchnitzel 3mo agoAn LLM definitely can do that work, but LLMs have a tendency to follow the path of least resistance unless you force them to do things properly and carefully supervise them.
- skeledrew 3mo ago> LLMs have a tendency to follow the path of least resistance That's a really strong motivation for the Rust port. It's literally impossible to take a path not leading to an unacceptable outcome because the Rust compiler fails the compile if code no longer marked "unsafe" is still actually unsafe, and the tests fail if the implementation is incorrect. The compiler actively helps to force the LLM to do things properly.
- throwaway613746 3mo ago[dead]