4 ms·
> routes!(...) > routes_with_openapi!(...) Macros, macros everywhere. I understand their use in basic functions like println!(), but I'm worried too much macr
by deepsun 7y ago
> routes!(...)
> routes_with_openapi!(...)
Macros, macros everywhere. I understand their use in basic functions like println!(), but I'm worried too much macros in client code will lead to problems (unreadable, clashes that will need custom names). If there are no problems with macros, why not making every function a macro then?
- steveklabnik 7y agoRocket takes the position (or at least, this is what I understand, maybe it's changed) that developer ergonomics are the most important thing. Macros can significantly clean up boilerplate, and so Rocket tends to use a lot of them. There are other options if you disagree, but this approach has gained it quite a following.
- AgentME 7y agoMacros let you do work at compile-time like inspect the types of their parameters. A macro can do things like automatically generating code that converts function's return type into a JSON string. If you need that, use a macro, but otherwise, you can and probably should use a function.
- dgb23 7y agoMacros are extremely important to make rust productive. It sometimes feels as if you were writing in a higher level language. One of the best examples is the serde crate. What a beautiful library!
- kibwen 7y agoMacros are powerful, but they should be used sparingly because they often have outsize effects on compilation times and degrading error message quality. I personally give myself a "macro budget" where macro-based solutions are prioritized based on benefit to a particular project.
- pjmlp 7y agoWith great power comes great responsibility. Based on my experience with macros, across several languages with support for them, macros are beautiful until you need to debug them under time pressure on a critical customer issue on a code base that you never seen before.