5 ms·
Zig's comptime is not macros, it's staged programming / multi-stage programming.
by deredede 2y ago
Zig's comptime is not macros, it's staged programming / multi-stage programming.
- Ygg2 2y agoZig comptime is a C++ template done better. It also suffers from similar issues as C++ templates. You can't know function is comptime unless you put it in comptime and it passes. See https://typesanitizer.com/blog/zig-generics.html https://typesanitizer.com/blog/zig-generics.html
- pjmlp 2y agoC++98 templates done better, we are past that now in C++23. Also D and Circle, done it before Zig.
- andrepd 2y ago>we are past that now Jesus, we very much aren't. The only real step improvement was in C++11 which added constexpr which (in the following years) gradually obviated the need for C++98 style TMP. But there really hasn't been much of a generational improvement since (OK, concepts I guess), and it remains cumbersome and error prone and difficult to debug.
- pjmlp 2y agoIf I compare C++98 template metaprogramming with tag dispatch, ADL, and SFINAE, with what C++23 offers, it is already a complete different world, even if there are still warts to improve.
- samatman 2y agoThis blog post is disqualified from any serious discussion, because it doesn't know the distinction between templates, which Zig's comptime constructs are not, and partial evaluation with reified types, which Zig's comptime constructs are. It's not possible to make a positive contribution after a mistake that basic. Here's an example of someone getting the design space correct, and therefore contributing to the discussion in a positive way. He doesn't end up liking Zig, for reasons I disagree with, but he does completely evade being not-even-wrong, which is table stakes. https://hirrolot.github.io/posts/why-static-languages-suffer-from-complexity.html https://hirrolot.github.io/posts/why-static-languages-suffer...
- Ygg2 2y ago> This blog post is disqualified from any serious discussion, because it doesn't know the distinction between templates Just because a blog doesn't go full type theory doesn't disqualify it from drawing conclusions based on experience and limitations incurred during actual use. Something can be very well typed but still suck to use. Intution doesn't need to be based on formal understanding. See Table of elements. Created by grouping elements by behavior, it turned out to be based on electron orbital configuration.
- samatman 2y agoThe central claim is that Zig's use of comptime is similar enough to templates to conflate them. That's simply incorrect. There's no value in trying to extract information from something which makes such a basic mistake as that, it doesn't contribute to a discussion, it distracts that discussion down a blind alley.
- Ygg2 2y agoI think it's insightful to some extent. The problems encountered in C++ templates apply to Zig's comptime as well. And their solution seem to be along same lines, i.e. add constraints. Edit: on re-reading the author doesn't understand why negative traits in Rust are a problem (not is basic boolean operation). I think they are abstracting too much and saying cows should be roughly spherical and water should roughly be a superconductor.