A good rule of thumb is that you should know exactly what your macro is converting things to, otherwise the macro has gone too far. For example, GitHub - SciML/MuladdMacro.jl: This package contains a macro for converting expressions to use muladd calls and fused-multiply-add (FMA) operations for high-performance in the SciML scientific machine learning ecosystem is fairly clear what it does: it just finds things like a*b + c
and turns it into muladd(a,b,c)
. These then nest, so a*b + c*d + e*f
becomes muladd(muladd(...)..)
. Do you know how to do it by hand? Yes. Do you want to? No. That’s a good spot for a macro.
Even when making a DSL, I think the “non-DSL” version should be very clear. For example, I wish JuMP had documented their macro-free interface, so the macro was “just nicer syntax”.