News for hackers. Stuff that matters.
Re:How to make your C codebase Rusty: rewriting keyboard fir... by cmcd on Thursday November 21, 2019 @12:34PM (#21596818)
More powerful macros and full unicode support feel like advantages to me.
Re:How to make your C codebase Rusty: rewriting keyboard fir... by akira2501 on Thursday November 21, 2019 @12:48PM (#21597025)
Advantages with a price.

The macros in the original code most all seem to be constants and very few functions, so I'm not sure what the power of Rust's macros buys here. I don't see a lot of difference between

    LT(3, KC_TAB)
and

    [TAB &LT{3}]
Both are "magical". Likewise, I can also understand the layout precisely by looking at the C code. To understand the Rust code, I have to assume what layer! and r! are doing, or I have to inspect them to make that determination.

I'm _sure_ Rust has advantages in certain situations, I'm not sure this is a great example to display that.

Re:How to make your C codebase Rusty: rewriting keyboard fir... by unlinked_dll on Thursday November 21, 2019 @01:03PM (#21597208)
The macro system is stupidly powerful but I agree this isn't a decent example. C preprocessor macros are very cumbersome not only to read and write, but to use.

I alluded to this is another comment but Rust macros can call arbitrary Rust code. Including file i/o at compile time, such as loading a config file in your syntax of choice, deserializing it to a struct, and then using it to synthesize tokens. Rust's macros become an extremely powerful tool for code generation using Rust itself.

Re:How to make your C codebase Rusty: rewriting keyboard fir... by flukus on Thursday November 21, 2019 @06:23PM (#21600865)
They come at the cost of readability and complexity, sometimes it's a good trade off but too much magic can make systems horrible to maintain. You often still have to know what a macro is doing by jumping to the code and it's a lot easier to mentally parse text replacement.

It's also the sort of complexity caused by developers that live in IDE's, outside of that it's rather trivial to add a build step with powerful language independent code generation tools.

Also, when someone inevitably takes macros why to far and you have to debug them, what is the rust equivalent of gcc -E/-save-temps to see the intermediate code? I assume it does but the lack of such features can be a nightmare working with attribute/annotation driven code in c#/java.