Zig's comptime is bonkers good

Overall view of Zig’s comptime

  • Many commenters find Zig’s comptime unusually coherent: the same language and syntax handle generics, reflection, constant evaluation, and small-scale codegen, instead of separate systems (templates, macros, traits, etc.).
  • Strong use cases mentioned: generic containers, compile-time reflection over struct fields (e.g., serialization, formatting), precomputing complex data, and generating specialized structs or “run” methods (e.g., neural nets on the stack).

Comparisons to other languages

  • C++: Upcoming C++26 reflection + existing constexpr/consteval could match much of this, but people worry about C++’s bloat, interactions with legacy features, inconsistent implementations, and long lag until production use.
  • D, Nim, V, Mojo, Scheme, Lisp: Several note that similar compile-time execution and metaprogramming have existed for years; supporters argue Zig’s novelty is ergonomics and being designed around this from the start.
  • Rust: Many like Rust’s safety but dislike macros/trait-level metaprogramming and slow compile times; some wish Rust had Zig-style comptime. Others defend Rust’s more parametric, constraint-based generics.

Generics, parametricity, and type reasoning

  • Debate over Zig-style “duck-typed” generics vs parametric generics:
    • Critics: arbitrary comptime logic on types breaks parametricity, makes reasoning and separate compilation harder, and pushes some errors to instantiation time.
    • Defenders: flexibility and simplicity outweigh the loss; you can encode many higher-level features (concepts, typeclasses) in comptime; humans can always read the source when types aren’t fully descriptive.

Ergonomics, tooling, and readability

  • Some find comptime straightforward; others say complex usages become hard to understand or debug and risk “when all you have is a hammer” overuse.
  • Concerns: hard to tell what runs at compile time vs runtime, impacts on IDE features (go-to-definition, refactoring, docs for generated types), and weak or immature Zig tooling/docs.
  • Proposed mitigations include better error messages, editor visual cues for comptime, and higher-level helpers in the standard library.

Compile-time execution, security, and build model

  • Discussion about compile-time performance and incremental compilation; large comptime-generated structures (e.g., 100MB NN) can compile in minutes but are “tolerable” for some.
  • Security concerns about running arbitrary code at build/IDE time are raised; others point out that existing build systems already execute arbitrary scripts.
  • Ongoing tension between built-in metaprogramming and external code generators: external tools are easier to debug and test, but many see them devolving into fragile DSLs, whereas in-language comptime is more integrated but harder for tools.