|
|
Subscribe / Log in / New account

A GPIO driver in Rust

A GPIO driver in Rust

Posted Jul 20, 2021 10:12 UTC (Tue) by ras (subscriber, #33059)
In reply to: A GPIO driver in Rust by bredelings
Parent article: A GPIO driver in Rust

I've never been a fan of lines of code as a measure of code size. It's highly dependent on coding style. I prefer token count.

Using vim as a very rough tool to break the code into tokens yields: C = 2134 tokens, Rust = 2261 tokens.

I expected Rust to be higher than C. Putting all that type information on each line comes at a cost. I am somewhat surprised the cost is so only 6%. It might even be within the error margin of my rough tool.


to post comments

A GPIO driver in Rust

Posted Jul 20, 2021 10:54 UTC (Tue) by pbonzini (subscriber, #60935) [Link]

I agree it's not bad and definitely within noise. The languages are different enough that a precise comparison is impossible: I don't know what your tool looks like, but e.g. gpio::LineDirection::Out might be 3 or 5 tokens whereas GPIO_LINE_DIRECTION_OUT would be 1; and while C might have more "static"s, Rust might have more "mut"s.

The thing that surprises me the most is how different it looks from C. For example I couldn't follow how the irqchip can be used from C code, all I could see is an implementation of irq::Chip.

That on one hand means that the bindings are idiomatic, on the other hand it means the Linux code base would be split in two even more than I expected.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds