Hacker News new | ask | show | jobs
by bpicolo 2731 days ago
Procedural macros are something you more or less never need to write in application code, but they add tremendous power to libraries
2 comments

Deriving typeclass implementations is something I do all the time in regular application code (in Scala), once you're used to it it gives you a lot of safety and expressive power. It sounds like Rust would benefit from some kind of record system / generic representation of traits (like we get from Shapeless in Scala) so that generic trait deriving could be written in normal code without needing macros.
Isn't Shapeless based in macros?

That said, an equivalent library in Rust would be very useful.

Shapeless has one or two macros in its implementation, but as far as the rest of the ecosystem is concerned it might as well be part of the language. The point is that you can implement a custom typeclass and derivation of instances of that typeclass for struct-like ((possibly recursive) compositions of) sum/product types without ever having to write a custom macro.
Which doesn't make it easier, since you might want to structure part of you application code as a reusable library.
It is entirely optional. I use Rust for two years now and work on a few things (biggest one around 10kLOC). I didn’t even read the Macro section in my books yet. Because I didn’t need to.
Most of the complexity of C++ is entirely optional too. That doesn't make the observation any less valid.