|
|
Subscribe / Log in / New account

A pair of Rust kernel modules

A pair of Rust kernel modules

Posted Sep 14, 2022 11:08 UTC (Wed) by khim (subscriber, #9252)
In reply to: A pair of Rust kernel modules by wtarreau
Parent article: A pair of Rust kernel modules

> Are there really people who can parse this ?

Sure. It's actually easier to parse than something like void (*signal(int, void (*)(int)))(int);.

I mean: is it a function? Or pointer? Where are arguments? Heck, how many arguments are there?

Rust code can be parsed from left to right, at least.

> And how is that supposed to be pronounced ?

How is the definition of signal is supposed to be pronounced?

> There are 16 symbols for 24 alphanumeric chars in this statement

And 13 symbols for 20 alphanumeric chars in C is, somehow, radically better?

> It's totally cryptic to me :-(

Well… if you don't know the language, of course it would be cryptic. But Rust syntax while ugly, serves a purpose: it makes code similar to C++. And, as I have already mentioned, is actually easier to parse than C or C++. Yes, it's punctuation-heavy, but you can blame C and C++ for that: most sigils have come into Rust from there. Only 'a is new but Ada uses such syntax, too.

I still hate Rust syntax (much less elegant than it could have been), but it's useful uglyness: it makes Rust look superficially similar to C++. Which is important mimicry not to spook C++ developers before they would be hooked.


to post comments

A pair of Rust kernel modules

Posted Sep 14, 2022 19:33 UTC (Wed) by Dr-Emann (guest, #136829) [Link]

For anyone actually trying to parse the signal type, it helps a lot to have a typedef:
typedef void (*sighandler_t)(int);
sighandler_t signal(int signum, sighandler_t handler);
The equivalent in rust is still pretty readable without a typedef:
fn signal(signum: c_int, handler: fn(int)) -> fn(int)


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