Hacker News new | ask | show | jobs
by bsder 1046 days ago
Zig has a decent chance of being an actual embedded device (ie. no operating system) programming language.

In my opinion, Zig seems likely to grow the necessary bits to be good at embedded while Rust is unlikely to figure out how to shrug off the clanky bits that make it a poor fit for embedded devices.

However, I'm a personal believer that the future is polyglot. We're just at the beginning of shrugging off the C ABI that has been preventing useful interoperability for decades.

Once that happens, I can use Rust for the parts that Rust is good for and Zig for the parts that Zig is good for.

1 comments

> clanky bits that make it a poor fit for embedded devices.

What do you see as "clanky bits that make it a poor fit" for such a broad range of stuff as "embedded devices" ?

Embedded goes at least as far as from "It's actually just a Linux box" which is obviously well suited to Rust, to devices too small to justify any "high level language" where even C doesn't really fit comfortably. Rust specifically has no ambitions for hardware too small to need 16-bit addresses, but much of that range seems very do-able to me.

Example clanky bit: memory ownership rules.

There are lots of systems where memory changes hands. Game programming, for example. You allocate a big chunk of memory, you put some stuff in it, you hand it off to the graphics card, and some amount of time later the graphics card hands it back to you.

Rust gets VERY cranky about this. You wind up writing a lot of unsafe code that is very difficult to make jibe with the expectations of the Rust compiler. It's, in fact, MUCH harder than writing straight C.

Example clanky bit: slab allocation

You often don't really care about deallocation of objects in slabs in video games because everything gets wiped on every frame. You'd rather just keep pushing forward since you know the whole block gets wiped 16 milliseconds from now. Avoiding drop semantics takes (generaly unsafe) code and work.

I see, so by "embedded systems" you meant a video game console ?
Yes, although I could have just as easily said "low-level systems programming" as embedded. I try to keep in mind that when people say "embedded" they may mean anything from ARM Cortex M series to Raspberry Pi 4s.

Rust is really good when it is control of everything. I love Rust for communication stacks (USB, CANBUS, etc.). Bytes in/state in to bytes out/state out is right in its wheelhouse. Apparently Google agrees--their new Bluetooth stack (Gabeldorsche) is written in Rust. When Rust has this kind of clearly delineated interface, it's really wonderful.

However, Rust does not play well with others as my examples point out. To be fair, neither do many other languages (Hell, C++ doesn't play well with itself). However, that's going to be a disadvantage going forward as the future is polyglot.