Hacker News new | ask | show | jobs
by general_ai 3426 days ago
> designed for embedding

Yet implemented in Rust. Why? If you want adoption, the best way to design something "for embedding" is to write it in C.

3 comments

It's designed to meet our embedding needs: in Firefox for desktops, Firefox for Android, Firefox for iOS, and Project Tofino (Node + Electron).

Widespread adoption a la SQLite is not one of our goals.

Rust meets our goals just fine… and it also produces demonstrably more correct software than C, which is important to us. (Not to mention leveraging the borrow checker and data race avoidance to provide safe near-automatic parallelization, which is a neat trick that's not in C's quiver.)

I would rather build Mentat in Swift or JavaScript than in C.

Rust embeds almost as well as C.
Be that as it may, it's a relatively obscure and quickly changing language, that _ends up calling into C_ anyway.
Rust doesn't change in a backwards incompatible way.

> that _ends up calling into C_ anyway.

What specifically do you mean here?

Says there it uses sqlite.
Datapoint: GNOME's Federico Mena Quintero is working on a file-by-file port of librsvg to Rust. Compiled Rust objects are linked with compiled C objects. Both Rust and C call functions in librsvg's C dependencies, such as Cairo. None of this is weird; it's precisely what Rust was designed for.
Correct. That has no bearing at all on whether it's smart to write the rest of the library in Rust.

Most non-trivial applications will at some point call out into code written in C, or compiled from some other language. So what?

Ah I thought you meant Rust generally, not this project. Makes sense!

(I still don't think that's enough to justify using C over Rust here, just that I understand you now.)

Because a Rust library is safer, equally efficient, faster to develop, easier to build and can expose a C interface.