4 ms·
Very powerful technique. However, one of my C++ coding rules of thumb these days is 'can I step through it in the debugger?'
by osullivj 11y ago
Very powerful technique. However, one of my C++ coding rules of thumb these days is 'can I step through it in the debugger?'
- CyberDildonics 11y agoYeah, that's a very good point, macros are really difficult to debug. They are one of a dozen things in C++ that I use 'almost never' but still use.
- agumonkey 11y agoIt's a great rule for any metaprogramming task. When writing a macro, or reflective intercession, make it a shim that wraps non-metalevel code, so it's decoupled, testable and yes debuggable.
- ra88it 11y agoInteresting. Do you have an example or a link to an example?
- agumonkey 11y agoI can't find the exact quote nor site, but it's a common advice in lisp tutorials to write the macro as thin as possible and split its internal logic as tiny composable functions (the usual desired lisp/engineering style). The rest comes from my small experience, in college we had a project patching java bytecode on the fly, you could generate correct logic at the bytecode level, but you would lose all the benefit of high level language (typechecking, debugging). One team had this excellent idea to just write the smallest bytecode hook/wrapper that would then call normal Java code.