10 ms·
I don't know, to me the C version is more readable. I know for sure that in the end the C macros will only do text replacement, whereas the Rust macros could do
by clktmr 7y ago
I don't know, to me the C version is more readable. I know for sure that in the end the C macros will only do text replacement, whereas the Rust macros could do anything.
And emojiis in code, really?
- Analemma_ 7y ago> I know for sure that in the end the C macros will only do text replacement, whereas the Rust macros could do anything. My impression is exactly the opposite: Rust macros are guaranteed to expand to syntactically valid code that still obeys the memory/type/lifetime-safety constraints, whereas C macros can expand to something that won't even compile, never mind have any guarantees about soundness. Not to mention all the hoops you have to jump through with extra parens and whatnot to avoid the footguns of C macro operator precedence.
- F-0X 7y agoRust macros can do worse things than C macros can. They can execute arbitrary code at compile time.
- cdirkx 7y agoThat is only with procedural macros. Normal macros operate just by token substitutions. Procedural macros are also special in that they are the only macros that can be 'unhygenic': creating new identifiers in the current scope that were not passed as an argument to the macro. (Although knowing if something is a procedural macro or not is not obvious when using one in code)
- juped 7y agoNot compiling is a great outcome when you've introduced an error.
- Lev1a 7y agoThat's the same for Rust macros though. If the expanded code does not pass all the checks along with the other/normal code the program/lib won't compile.
- cmcd 7y agoMore powerful macros and full unicode support feel like advantages to me.
- akira2501 7y agoAdvantages 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 <{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.
- unlinked_dll 7y agoThe 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.
- flukus 7y agoThey 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.
- monocasa 7y ago> And emojiis in code, really? For something like the representation of keyboard icons that have unicode support specifically to support use cases like this? Why not?
- mitchty 7y agoYep, as weird as it would be for me to see it, if its in unicode who cares, a glyph is a glyph.
- umanwizard 7y agoBecause it is very unlikely to display correctly (let alone be typeable) on all the systems where Rust development is supported. (I left a longer version of this comment elsewhere.)
- monocasa 7y agoWhat about ß?
- umanwizard 7y agoI would reject any code review containing that character too, unless I worked on a project that used German internally, or was creating a product targeted towards the German market in some way.
- winrid 7y agoI have this issue too. I'm not even a C developer but I can understand it. I'm a fan of the idea of rust but when I see it my eyes glaze over.
- staticassertion 7y agoYeah, I feel this way about French. I want to like the language, but every time I try to read it I can't seem to understand what the words are trying to tell me.
- psv1 7y agoYes, Rust is by far the most unreadable language that I've tried. I really wanted to like it but everything is just so ugly, unclear, and (seemingly) unnecessarily complicated.
- saagarjha 7y agoWorse than C++?
- dman 7y agoIs that the bar?
- liamdiprose 7y agoIt's the sanity check to see if a language really is the worst someone has seen.
- dman 7y agoGiven how often the C++ complexity argument is made, I am genuinely concerned that Rust will fully deliver on its promise on being simpler than C++. Only in retrospect will it be evident that it was the wrong goal to shoot for all along the way.
- bluejekyll 7y agoI don’t think Rust has ever promised to be simpler than C++. It is simpler, in my opinion, but while I think it’s probably a good goal to shoot for, I’ve never seen anything that says it is an explicit goal of the language. It does go out of its way to be ergonomic, which could be interpreted as simpler.
- discardable_dan 7y agoBrainfuck exists. It's fine.
- outworlder 7y ago> And emojiis in code, really? What is the problem? As most code nowadays is UTF, why do you care?
- smabie 7y agoI mean, I guess? But I’m guessing way over 99% of lines of code is ASCII. Of course then it’s also UTF-8, but it’s still a little disingenuous to say that “most” code is Unicode.
- clktmr 7y agoAre you coding on your phone? Emojiis are not on my keyboard. Maybe not even in my font.
- steveklabnik 7y agoI'm on Windows, emoji are a "windows + ;" away. On a Mac they're "command + control + space". Not sure about Linux.
- umanwizard 7y agoI have no idea how to type emojis on Linux (with a barebones tiling WM), the OS I use almost exclusively for work, although I’m willing to believe there’s probably a way. But I would still immediately reject a code review inserting emojis into our codebase — why force every single person who modifies the code to figure out how to type them in their setup, use a particular font, etc. I’d also reject a code review naming things in Chinese or French, for similar reasons, unless I worked in a country that uses one of those languages. Furthermore, Windows, Mac, and Linux are not the only operating systems, nor even the only ones Rust supports. Good luck figuring out how to type emojis on Solaris or the GUI-less FreeBSD base system.
- tom_mellior 7y ago> I have no idea how to type emojis on Linux (with a barebones tiling WM) You can copy and paste. In the context of this project, the small, fixed set of symbols (not emojis, but whatever) makes a lot of sense, and the code comes with an example that you can copy from. I would guess that this works even on Solaris or in a decent editor on GUI-less FreeBSD. As for using, I don't know, "thumbs up" and "thumbs down" symbols in place of "true" or "false", sure, that would be excessive.