2 ms·
I haven't read the article yet, but this seems to conflate compile time evaluation with metaprogramming. Not all comptime evaluation is metaprogramming. I would
by Zambyte 1y ago
I haven't read the article yet, but this seems to conflate compile time evaluation with metaprogramming. Not all comptime evaluation is metaprogramming. I would argue the majority of comptime programming as it is used in Zig isn't even metaprogramming. Metaprogramming is a paradigm where there source or target data structure is primarily the language you're programming in. comptime evaluation of expressions that could be runtime evaluated is not that. I would argue that comptime evaluation of expressions that return comptime only values (like types) is not even inherently that.
Where you start to see actual metaprogramming in Zig is in functions like @typeInfo, @alignOf, @offsetOf, which actually let you operate on language constructs (ie: looping over the fields of a struct). This is not extremely out of the ordinary, but it's not done "as much as possible".
Another place that metaprogramming shows up in Zig is code generation using the build system. I've never done this, and I would argue this is usually recommended to be done as little as possible, rather than as often as possible.
Edit: I read the article, and while I think that the author was wrong about Zig pushing metaprogramming "as much as possible", they were fairly accurate in how it is used in the rest of the article, like for serialization. The thing is, most of my programs are not serialization. I use serialization as a means to do other things.
- throwawaymaths 1y ago@alignOf is almost never metaprogramming, it's almost always just something you have to call to declare to the compiler, yes (eyeroll), i am aware that this type erased pointer is aligned correctly. however, it's also a good signal "please review this code to make sure i didn't f it up"