3 ms·
Having done some Rust macros, the entire thing is such a huge hidden wart. Even very simple meta-programming in Rust need to be in their separate crate and has
by 127 1y ago
Having done some Rust macros, the entire thing is such a huge hidden wart. Even very simple meta-programming in Rust need to be in their separate crate and has to use very complex syntax and invocation.
Also the whole "don't write macros" is such a hilarious statement given that entire Rust ecosystem is built on them.
- airstrike 1y agoI agree Rust macros are cursed in many different ways but > given that entire Rust ecosystem is built on them. I don't think the people saying "don't write macros" are the same people building an entire ecosystem on top of them The iced crate has virtually zero macros by design.
- spoiler 1y agoEh. I agree there's complexity in them, and that a lot of the ecosystem indirectly use them because of derive macros, but I wouldn't call it a wart, and the "syntax" for writing proc macros isn't that bad if you use the syn/quote crates. I agree that decl macros usually make me sigh and open the docs though
- nicoburns 1y ago> I agree that decl macros usually make me sigh and open the docs though Declarative macros are very like regex's: both in that at first they seem incredibly dense and arcane but once you work out how to read them they're actually very simple, and in that the syntax is literally similar in that it's a list of tokens that must match sequentially.
- pjmlp 1y agoIf regexp was simple there would not exist universities dedicating a semester to its theory and various implementation algorithms, alongside a famous quote. :)
- tialaramex 1y agoUniversities are teaching about the Regular languages and about Finite automata. So if we're saying this means regex isn't simple then - having observed that my University's Math course has two semester long Number Theory courses we must conclude that the integers aren't simple either, right ? And yet, the integers are simple enough that's where we start five year olds, by counting things. Simple and Shallow are not the same thing.
- pjmlp 1y agoIndeed they aren't, that is why math has such a bad reputation in most countries, already at basic school levels. Recent article this week in German press, as per IQB-Bildungstrend 2024 results, one third of students fail in math exams. Which reinforces the common culture that math is hard, and it is to be expected not to have great grades at it.
- pjmlp 1y agoIt is its own can of worms, and maybe it is due to me using the language on and off since 1992, but I find what is possible in C++23, much easier for metaprogramming as the few times I had to understand trying to implement Rust macros. C++26 reflection will make this much easier, without having to depend in stuff like the syn crate. I wonder if going with two macro systems, each with its own syntax and approach, was such a good idea.
- IshKebab 1y agoMaybe "don't write your own macros". I guess it's like C++ template meta programming. If you find yourself using that a lot, it's probably a bad sign. But also Eigen is pretty great.
- TinkersW 1y agoI dunno, the C++ template implementation of this macro would be far easier to read as it is just normal C++.
- IshKebab 1y agoC++ templates are totally different feature. You couldn't do this with C++ templates. It was just an example of something that gets very hairy for library implementers but is still quite nice for users.
- ameliaquining 1y agoMacros by example, which is what this post is about, don't have to be in a separate crate.