Hacker News new | ask | show | jobs
by kangalioo 1775 days ago
Interesting. Isn't that a good fit for macros though? Particularly for the future maintainers sake. With macros, future maintainers will only need to tweak macro invocations or macro bodies, instead of having to do a huge copy paste job all over again
2 comments

And then you have to waste couple of hours to do the macro which might or might not be used in the future.
Even when I have to look up all the weird syntax for a macro_rules! macro, they take like 10 minutes, tops. If you're taking much longer than that, you're probably trying something too ambitious: it should either be proper code generation (in Rust, a build script or proc macro) or a const fn, or a trait and proper generics.

C's even easier; you just write the C code with parens around everything, then run it through cpp, then correct any divergences from the expected code. (It does take a bit longer, though, because the compiler waits until the last minute to shout at you if you make a syntax error.)

I can see complicated C++ templates taking hours, but they're not really macros. (They're probably the correct tool for this, though.)

possibly, I know in some industries you can't use macros due to security audits