typesanitizer
typesanitizer.com · Personal blog · on HN since 2021
typesanitizer is a programmer's blog on language design, compilers, generics, effect systems, optimizers and software engineering practice.
What HN saysHN commenters debate its post arguing Zig-style comptime generics are poorly suited to most languages, citing issues with type checking and C++ template similarities.
20HN people shared it
5linked it in comments
26stories submitted
1.1Kstory points
3 months agolast shared
2021people per year2026
Most-shared posts
- 1Zig-style generics are not well-suited for most languages6 people · 199 points · first shared 2022 · 128 comments on HN
- 2Leaving my last job [at Apple]3 people · 29 points · first shared 2024 · 1 comments on HN
- 3Deeper theories of program design3 people · 9 points · first shared 2025 · discussion on HN
- 4Experience Report: 6 months of Go2 people · 297 points · first shared 2022 · 262 comments on HN
- 5Optimizers need a rethink2 people · 149 points · first shared 2024 · 167 comments on HN
- 6The purported benefits of effect systems2 people · 33 points · first shared 2025 · 3 comments on HN
- 7A programmer's field guide to assertions2 people · 7 points · first shared 2025 · discussion on HN
- 8Job queues are deceptively tricky2 people · 4 points · first shared 2026 · discussion on HN
- 9Reviewing Code Is a Skill2 people · 4 points · first shared 2026 · discussion on HN
- 10An epic treatise on error models for systems programming languages1 people · 221 points · first shared 2025 · 76 comments on HN
- 11Meta-analysis of three different notions of software complexity1 people · 109 points · first shared 2025 · 19 comments on HN
- 12Six Programmers and the Type System1 people · 17 points · first shared 2025 · discussion on HN
- 13An opinionated beginner's guide to Haskell in mid-2019 (2019)1 people · 3 points · first shared 2024 · 1 comments on HN
- 14How should we learn from bugs?1 people · 2 points · first shared 2025 · discussion on HN
- 15Principled Ad-Hoc Polymorphism (2018)1 people · 2 points · first shared 2024 · discussion on HN
What HN people wrote when they linked it
jmull · 2025-01-07
> being able to reason about functions just from their type signature.
This has nothing to do with compile-time execution, though. You can reason about a function from its declaration if it has a clear logical purpose, is well named, and has well named parameters. You can consider any part of a parameter the programmer can specify as part of the name, including label, type name, etc.
> There is a good discussion of some issues here: https://typesanitizer.com/blog/zig-generics.html
That's actually not a great article. While I agree with the conclusion stated in the title, it's a kind of "debate team" approach to argumentation which tries to win points rather than make meaningful arguments.
The better way to frame the debate is flexibility vs complexity. A fixed function generics system in a language is simpler (if well designed) than a programmable one, but less flexible. The more flexibility you give a generics system, the more complex it becomes, and the closer it becomes to a programming language in its own right. The nice thing about zig's approach is that the meta-programming language is practically the same thing as the regular programming language (which, itself, is a simple language). That minimizes the incremental complexity cost.
It does introduce an extra complexity though: it's harder for the programmer to keep straight what code is executing at compile time vs runtime because the code is interleaved and the context clues are minimal. I wonder if a "comptime…
pcwalton · 2025-03-22
How do you typecheck generics, with type inference, with comptime?
Or, more generally, address all the issues raised in [1]. You're saying that comptime can fully replicate all the features that a proper generics system has, which is plainly false.
[1]: https://typesanitizer.com/blog/zig-generics.html
Ygg2 · 2025-03-22
Zig 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
froh · 2024-10-28
in the "closing thoughts" [1] of the OP article there's a pointer to "Proebstrings law" [2] which got me to a benchmark [3] how LLVM has improved over 10 years from 2.7 to 11
which leaves me with the strong intuition that indeed what mit benefit more from a rethink is not optimizers but focus on programmer productivity
> Perhaps this means Programming Language Research should be concentrating on something other than optimizations. Perhaps programmer productivity is a more fruitful arena.
[1] https://typesanitizer.com/blog/rethink-optimizers.html#closing-thought…
[2] https://proebsting.cs.arizona.edu/law.html
[3] https://zeux.io/2022/01/08/on-proebstings-law/
noelwelsh · 2025-01-07
It would be nice to have a more indepth discussion of the issues that have been found with compile-time programming, rather than uncritical acclaim. Staged programming is not new, and people have run into many issues and design tradeoffs in that time. (E.g. the same stuff has been done in Lisps for decades, though most Lisps don't have a type system, which makes things a bit more complicated.)
Some of the issues that come to mind:
* Implementing generics in this way breaks parametricity. Simply put, parametricity means being able to reason about functions just from their type signature. You can't do this when the function can do arbitrary computation based on the concrete type a generic type is instantiated with.
* It's not clear to me how Zig handles recursive generic types. Generally, type systems are lazy to allow recursion. So I can write something like
type Example = Something[Example]
(Yes, this is useful.)
* Type checking and compile-time computation can interact in interesting ways. Does type checking take place before compile-time code runs, after it runs, or can they be interleaved? Different choices give different trade-offs. It's not clear to me what Zig does and hence what tradeoffs it makes.
* The article suggests that compile-time code can generate code (not just values) but doesn't discuss hygiene.
There is a good discussion of some issues here: https://typesanitizer.com/blog/zig-generics.html