4 ms·
I feel that oftentimes runtime metaprogramming is to make up for code that can't be written down statically. But if you have the right macros then you don't nee
by bobbylarrybobby 3y ago
I feel that oftentimes runtime metaprogramming is to make up for code that can't be written down statically. But if you have the right macros then you don't need the metaprogramming to happen at runtime. For instance, Rust has a pretty solid type system (not quite Haskell, but more intricate than Java) and lets you do things like generate serialization and deserialization code for arbitrary structs at compile time, which most languages would do at runtime by inspecting fields or something similar.
All this to say, runtime metaprogramming doesn't seem inherently more capable compared to what's possible in the more “static compiler” languages; rather, it seems like an escape hatch for when you can't generate the code you want at compile time.
- kaba0 3y agoWhat I find absolutely intriguing is the existence of multiple compile/runtimes, like a Matryoshka doll. LISPs are most famous for attempting to solve this problem with their macro systems. The JVM ecosystem also has a very oft used, but more advanced case for this: runtime code generation. Depending on how dynamic your problem is this might be required and then “traditional compile-time” macros would not be enough.
- LAC-Tech 3y agoAll this to say, runtime metaprogramming doesn't seem inherently more capable compared to what's possible in the more “static compiler” languages; rather, it seems like an escape hatch for when you can't generate the code you want at compile time. It's by definition more powerful though, in that the runtime language is (hopefully) more powerful than the type description language. I'm not arguing that it isn't preferable to produce (de)serialisation code statically. Just that by definition it's more capable as it can do everything the runtime can.
- Fire-Dragon-DoL 3y agoWhat this person said. 15 years of ruby and all that metaprogramming is literally the most painful part. Funny, because I used to love it.
- munificent 3y agoYes, compile-time metaprogramming is a different approach that I'm personally really interested in. There are trade-offs as always, but it can give you much of the power of metaprogramming without totally killing static analysis.
- bradrn 3y ago> For instance, Rust has a pretty solid type system (not quite Haskell, but more intricate than Java) and lets you do things like generate serialization and deserialization code for arbitrary structs at compile time, which most languages would do at runtime by inspecting fields or something similar. For that matter, Haskell can do exactly the same thing, and as you note its type system is even more sophisticated than Rust’s.