4 ms·
I've run into the opposite issue. I like macro lists in C/C++ (not sure what people call them). It's the idea that you create a pre-processor list and then use
by asiachick 5y ago
I've run into the opposite issue. I like macro lists in C/C++ (not sure what people call them). It's the idea that you create a pre-processor list and then use that list to effectively code generate. For example you can use the list to generate enums, enum to string tables, case statements for all cases, etc.... It's clever but it's also IMO best practice because it prevents bugs. The reason they're used is it prevents the various parallel tables from getting out of sync. It's also arguably better than some external code generator because there are less dependencies.
So, is that a "clever" solution that should be avoided because it's "clever" or is it a best practice because it actually solves real problems? Problems which have cost me hours of debugging that could have been avoided if I'd just used the "clever" solution. For me it's the latter.
In fact, speaking to the OP, it also encodes the original programmer's logic since without them, the new programmer has to know the 4 to 9 places they'd need to edit to add to the list where as with them they only need to know 1.
- selckin 5y agoit's a workaround for a lacking type system
- atq2119 5y agoNot really. It'd be more accurate to say it's a workaround for an existing proper hygienic macro system built on static introspection and code generation.
- jstimpfle 5y agoNot really. It's not a workaround - it just works. Maybe most uses of lexical macros could be done with hygienic macros / macro replacement bodies that are fully formed expressions (AST nodes), but not all of them. For those macros, really the "hygienic" doesn't matter half as much as people pretend. Don't do complex macros where the "hygienic" is required. Don't generate code, write code. If you need to generate syntax to remove boilerplate, then sprinkle a few macros in. But to generate syntax, in general you'll need a lexical macro system.
- orwin 5y agoI'd say its not really a workaround, its a feature. And a hard one to use well. But as someone said in another comment, i think reading the preprocessor in C and especially C++ with the templating is really interesting and help a lot understand how the OG team behind the code used to work. Some tricks are "too clever" for me originally, but with proper documentation on these tricks, i understand tehm and sometime, i have a sudden hindsight/sudden clarity (i don't know how to say it, its a bit like entering the zone?)
- jhgb 5y agoSounds like that it's more a workaround for lacking a proper macro system.
- jstimpfle 5y agoHow is a straightforward solution to some development problem (create multiple language entities, like enum + data tables, from a single point of definition in the source code) a workaround for some lacking thing? Maybe you could clarify by posting a better version of what GGP suggested.