3 ms·
I’m referring to things like println, which isn’t a macro in any other language. If you want to stick with the serde example, then look at the diy name mangling
by alphanullmeric 3y ago
I’m referring to things like println, which isn’t a macro in any other language. If you want to stick with the serde example, then look at the diy name mangling in the deserializer trait:
https://docs.rs/serde/latest/serde/trait.Deserializer.html https://docs.rs/serde/latest/serde/trait.Deserializer.html
Or the copy and pasting in Axum:
https://github.com/tokio-rs/axum/blob/24f0f3eae8054c7a495cd364087f2dd7fa8b87e0/axum-extra/src/handler/mod.rs#L142 https://github.com/tokio-rs/axum/blob/24f0f3eae8054c7a495cd3...
- nightfly 3y agoPrintln is also much more complicated and expensive at runtime in "any other language"
- alphanullmeric 3y agoExcept for C++.
- pie_flavor 3y agoYou mean the language which, in every major implementation, that particular function is a macro?
- plorkyeran 3y agoNone of printf, iostreams, or std::fmt are macros in any implementation I'm aware of.
- pie_flavor 3y agova_arg, which drives printf, is what I was referring to, and is generally a macro, and printf is what I was assuming alphanullmeric was referring to. iostreams defeat the point, since Rust is just as capable of the functionality and indeed the exact syntax, and std::format uses the properties of templates that are exactly like macros in both benefits and drawbacks, templates being an unusual cross between macros and generics.
- alphanullmeric 3y agoWhat macro? https://en.cppreference.com/w/cpp/io/print https://en.cppreference.com/w/cpp/io/print
- nvm0n2 3y agoAre you sure? Java's println is pretty well optimized especially with the recent string builder optimizations.
- SkiFire13 3y agoI'm failing to see how this is relevant then. You say the issue is with macros in the first place, but then it turns out you're actually referring to other macros and have no alternative to the macro that actually created the problem. What am I missing in your reasoning?
- alphanullmeric 3y agoThe issue is with macros in general, and the problem is present with macros in general, even if there’s no better solution in this specific case. If someone is willing to take such drastic measures to combat the downsides of macros when they are needed, what would they be willing to do when they’re forced to use macros when they shouldn’t be needed?
- pie_flavor 3y agoThe drastic measure is because of the large amount of code serde generates. The features you describe, by contrast, do not involve much code from a macro standpoint and such macros would not benefit from precompilation. If you're complaining about something that TFA is not an example of, it's a good idea to at least provide something that is an example of it, because otherwise you're just yelling at clouds.