3 ms·
> Metaprogramming is often witchcraft. This is an advice I frequently see, and I disagree with it strongly. For some reason, people are irrationally afraid of
by TeMPOraL 9y ago
> Metaprogramming is often witchcraft.
This is an advice I frequently see, and I disagree with it strongly. For some reason, people are irrationally afraid of metaprogramming, as if it was a different kind of programming. It isn't. It's regular programming, following the very same rules, except that you're automating your own work now.
I don't know; maybe it's because mainstream languages absolutely suck at metaprogramming (if they allow it at all), so people are not used to it?
I mean, it's like someone calling algebra "witchcraft". It's not witchcraft, they just never bothered to learn it.
(Related, I see this approach of lowest-common-denominator programming being popular, and I believe it's very hurtful to everyone. Programming is a profession. If you don't understand some piece of code because it uses weird language features, suck it up and learn stuff, like a real professional.)
- linkregister 9y agoMetaprogramming frequently reduces readability of the code. Almost all Linux kernel developers and embedded systems programmers are familiar with the linked list composed only of #define 's, and other metaprogramming solutions. It doesn't mean that seeing things like that are readable or easily traced to reproduce what happened. Maybe you are so smart you can juggle it all in your head, as Torvalds is reputed to do with the Linux kernel. The rest of us don't have the ability to hold the mental model of both the primary layer and the metaprogrammed layer in our heads without a devotion of time that would exceed our schedules. Thankfully in C-like languages, the compilers I've worked with will let you see the post-metaprogrammed output. C++ templates and other metaprogramming features improve readability; I'm don't mean to cast shade on metaprogramming in general, just heavily obfuscated implementations.
- ThrustVectoring 9y agoThe problem isn't with writing or reading metaprogramming. It's in debugging issues in the program that the metaprogram writes. You have to then figure out what both the meta-code and the code does and how they interact to have a good understanding of the problem. There's also some very powerful advantages to avoiding metaprogramming. Like, "grepping for the name of a token shows all instances where said token is relevant". This is an incredibly powerful tool, and you really miss it when poking around in new codebases with lots of magic.