4 ms·
Good. Metaprogramming is programming -- it's scripting the compiler, to produce code that is faster (at runtime) or catches more errors at compile time. But fo
by kentonv 10y ago
Good.
Metaprogramming is programming -- it's scripting the compiler, to produce code that is faster (at runtime) or catches more errors at compile time. But for some reason in C++, metaprogramming is written in a completely different language from everything else -- a functional language, but not a very good one. As a result, code that relies heavily on metaprogramming ends up inscrutable to most programmers.
Instead, we should embrace metaprogramming and allow it to be performed in a language that is similar to other code, so that we can understand it. Give the compiler an actual API and let me write code that calls that API at compile time.
(I don't know enough about Rust to know how well they've accomplished this.)
- Manishearth 10y agoGenerics in Rust are supposed to be used as generics, not really for metaprogramming like this (but you can, but it won't be pleasant). But Rust has a hygenic higher-level macro system that helps. On top of that, Rust is getting procedural macros. Right now this is limited to `#[derive()]` macros, but we want it to cover all cases. This means that you can write a macro that runs arbitrary rust code at compile time. (While it currently is limited to `#[derive()]` macros you can abuse the API to make it work for inline bang-macros as well)
- deleted 10y ago[deleted]