logoalt Hacker News

prologicyesterday at 9:54 PM10 repliesview on HN

I just compared this Rust implementation against the original C sources. Some ~50k SLOC (Rust) compared to maybe ~8-12k SLOC of C (depending on if you count headers). Why is the Rust implementation so much more complex and onerous?


Replies

josephgyesterday at 10:07 PM

If the readme is anything to go by, this doesn't look like it was written by hand. Codex if I were to guess. I wonder the coding agent "improved" the code.

The readme hints at the prompt:

> It keeps the original system's semantics — what it does — while rethinking how it's expressed: stronger types, clearer module boundaries, idiomatic abstractions everywhere.

"idiomatic abstractions" would certainly bloat the line count.

show 2 replies
steveklabnikyesterday at 10:32 PM

For fun, I decided to take a look at a random syscall: fork.

* https://github.com/yuan-xy/Linux-0.11/blob/master/kernel/for...

* https://github.com/Poseidon-fan/linux-0.11-rs/blob/420152fdf...

The Rust is slightly shorter, though it also isn't organized in exactly the same way. The code isn't that different overall, creating and copying some data structures around, as you'd expect for a fork implementation of this vintage.

Maybe I got lucky, but I would expect that it's more of what other people said: this repository includes far more than the kernel.

dminikyesterday at 10:05 PM

According to this breakdown: https://ghloc.vercel.app/Poseidon-fan/linux-0.11-rs?branch=m...

It's about 15k lines of code for the kernel and the rest is various utilities, libraries and programs that can run on the kernel.

show 1 reply
BobbyTables2today at 1:14 AM

Longer isn’t always worse.

C code probably has no problem mixing and perverting int vs enum. Bitfields, structs, etc…

A rust program would define an enum and also implement handling of unexpected values (or consider them errors). Structs and bitfields would be more intentionally used.

Sure, Rust macros can avoid the boilerplate code, but overall line count may still increase a bit.

That said, I’d blame auto-generated code here as other commenters do.

Aurornisyesterday at 10:56 PM

This repo contains a lot of extra tools and userspace programs.

The majority of Rust the code in the repo is not for the Linux kernel.

binsquareyesterday at 9:58 PM

I don't think it's rust

ls-ayesterday at 10:30 PM

I like how everyone has a different theory as to why

icemanxyesterday at 10:27 PM

because of AI

broknbottleyesterday at 9:58 PM

More LoC means easier to quantify the impact when telling a story. The actual code quality may be lower but that’s the schmuck’s problem that comes after once promo is acquired.

show 2 replies
sudbyesterday at 9:58 PM

One of the tradeoffs of Rust is its verbosity I think (in return for which Rustaceans would say you gain explicitness).

show 2 replies