Live data from Hacker News

Rewriting in Rust

blog.jetbrains.com

11–20 of 68 posts

Re: Rewriting in Rust

#11
This post advocates rewriting incrementally instead of all at once. Just like Joel said back in 2000, and like everyone continues to always say to this day. Yet in practice, people don't actually do this; complete rewrites in Rust remain far more common than incremental ones, particularly when rewriting from a language other than C. The high-profile exceptions, like Linux, Windows, and Firefox, are codebases so huge and ancient that they obviously cannot be rewritten from scratch. When rewriting from scratch is an option, it tends to be taken.

The reason for this is pretty straightforward: Incrementally porting a codebase from another language to Rust (especially if it's not C) is a deeply unpleasant experience, because the interop tooling isn't good enough and you spend most of your time fighting it. Consider the case of rewriting from C++; in the simplest case, you use bindgen and cbindgen, which only work with extern "C" functions in both languages. So you effectively have to rewrite each API first from idiomatic C++ to C-in-C++, then translate to C-in-Rust, then rewrite again in idiomatic Rust. And then repeat for the next API. And so on. It's not going to take long for most programmers to go "screw it, I don't care what Joel said, at least when I rewrite all my work I'll be doing it in one language where anything can call anything else". cxx and autocxx modestly improve things, but still leave you with an impoverished API vocabulary and similar problems, and you still have to do the three-step rewrite for each API, one at a time.

This is also why TypeScript, Kotlin, and Swift worked so hard to have seamless two-way interop with JavaScript, Java, and Objective-C. Without that, they couldn't have credibly promised to replace the earlier languages (because large existing codebases where a rewrite wasn't economical would still be stuck with them), and so couldn't have gotten off the ground.

Crubit is supposed to fix this for C++-to-Rust, and I'm rooting really hard for it, but it's not there yet. For most other languages, a Crubit-like thing probably isn't even possible in principle, because the differences are too great.

(I'm not talking here about the use case where you started with a garbage-collected language but have hit a performance ceiling with it, so you rewrite just the most performance-sensitive parts in Rust, while continuing to develop the rest of the codebase in the original language. This is often a great way to use Rust, but it's solving an easier problem and so poses fewer difficult tradeoffs.)

Re: Rewriting in Rust

#12

Note, I am a co-maintainer of GNU coreutils. Whether that makes my opinion relevant, biased, or both, you can decide. :) I really wished the documented their benchmarking methodology here, or at least cautioned the reader not to jump to conclusions based on the benchmarks shown. GNU 'sort' performance can drastically be altered by the locale in use, the input, and the arguments given to the --buffer-size and --parall…

There’s none of those details because it’s an AI written article. It doesn’t even talk about the stuff it says it’s going to in the very first paragraph.

Re: Rewriting in Rust

#13
post #2

I think that a line-for-line rewrite in Rust like Bun did isn’t really getting all of the benefits of using Rust. A key benefit is utilizing the type system to make the borrow checker work for you by making certain checks happen at compile-time instead of runtime. Making it impossible for certain mistakes to occur is a massive benefit but you need to restructure everything to do so.

The Bun rewrite is a long-term investment; the idea is that you initially compromise on idiomatic Rust for the sake of being able to keep shipping, but then the codebase becomes more idiomatically Rust-like over time. It will probably take another year or so to determine whether this works out.

(Note also that Bun inherently needs to use a lot of unsafe because a large fraction of its internal API surface is interlinked deeply and pervasively with that of JavaScriptCore.)

Re: Rewriting in Rust

#15

Note, I am a co-maintainer of GNU coreutils. Whether that makes my opinion relevant, biased, or both, you can decide. :) I really wished the documented their benchmarking methodology here, or at least cautioned the reader not to jump to conclusions based on the benchmarks shown. GNU 'sort' performance can drastically be altered by the locale in use, the input, and the arguments given to the --buffer-size and --parall…

There’s none of those details because it’s an AI written article. It doesn’t even talk about the stuff it says it’s going to in the very first paragraph.

That's a really great point, and demonstrates a deep understanding of how AI is changing the landscape of writing online!

Re: Rewriting in Rust

#17
To me Rust is great where you don’t have to touch unsafe part. All the hard works are done by those skillful maintainers of the language and some core libraries such as tokio. I don’t see much value in it if either I have to work on the low-level stuff quickly (like implementing linked lists myself) or a complete high-level of i/o bound work like writing web servers.

Re: Rewriting in Rust

#18

I would love it if jetbrains were to speed up IntelliJ. I started a new job writing Java professionally last year and, up that point, I had no idea that IDE's could actually be that slow. My company gave me a brand new, beefy Macbook pro and that thing can barely handle IntelliJ sometimes...

Just use VS Code. Its Java support isn’t the best, but it’s good enough and the rest of the IDE makes up for it.

I feel like a lot of the love for IntelliJ is a sort of Stockholm Syndrome combined with relief at not using Eclipse.

Re: Rewriting in Rust

#19
> And then there’s the Stack Overflow Developer Survey.

Honest question, at what point is the Stack Overflow Developer Survey not representative of the average software engineer, many (most?) of who no longer use Stack Overflow?

Re: Rewriting in Rust

#20
> ... Part of this comes from auto-vectorization: the Rust compiler generates SIMD instructions automatically from a regular for loop, while most C implementations require hand-written SIMD...

I understand that their compiler in Rust is better. And any other language could compile it using the same SIMD instructions.

Post reply on HN