> One meta point to keep in mind: many of the points here mirror the downsides of dynamic typing in comparison to static typing (again, not to imply that dynamic typing is not sometimes useful), because in some sense, it is the same problem but in a different context – instead of run time vs compile time, we’re talking about instantiation time vs declaration time. Yes, you have more flexibility to do whatever you want, but the problem is that you have more flexibility to do whatever you want.
This is the first time I've seen something said so similarly to how I feel about what the article describes as "template"-style generics; it has a similar user experience to duck typing where you have to just use something that fits the expected shape where it's being used or else everything falls apart. The happy path where everything is done correctly is certainly less verbose, but at least personally I don't end up feeling like it's less work in the long run to have the errors that inevitably happen when I slip up take so much more effort to debug.
It's not just similar, templates are duck typed, they just happen to execute at compile-time.
I have mixed-feelings about them. On one hand they have all the problems mentioned in the blog post and most of the ones from duck typing in general.
On another hand not needing to define protocols for every little thing is pretty nice.
I think a nice middle ground would be to structuraly type them. Have the compiler record in some interface file of some sort exactly which fields/functions must be available for the template to work.
But I don't think such a thing is feasible with the insane metaprogramming you can do in zig or even C++ (which is also turing complete, just incomprehensible)
>This post is meant to discuss reasons why Zig-style generics are not well-suited for languages other than Zig. Zig’s generics are in some sense well-suited to Zig, because they line up with the language’s philosophy that it is very important to have fewer concepts rather than more concepts.
>However, most languages don’t share that philosophy, at least, not as strongly as Zig does.
Bryan Cantrill talked about values of different programming languages [1] and I think it's a particularly useful way to compare different languages and the choices they make when developing them.
It often seems that criticism that is directed at a language is simply a reflection of a difference in values.
6 comments
[ 0.16 ms ] story [ 37.5 ms ] threadThis is the first time I've seen something said so similarly to how I feel about what the article describes as "template"-style generics; it has a similar user experience to duck typing where you have to just use something that fits the expected shape where it's being used or else everything falls apart. The happy path where everything is done correctly is certainly less verbose, but at least personally I don't end up feeling like it's less work in the long run to have the errors that inevitably happen when I slip up take so much more effort to debug.
I have mixed-feelings about them. On one hand they have all the problems mentioned in the blog post and most of the ones from duck typing in general.
On another hand not needing to define protocols for every little thing is pretty nice.
I think a nice middle ground would be to structuraly type them. Have the compiler record in some interface file of some sort exactly which fields/functions must be available for the template to work.
But I don't think such a thing is feasible with the insane metaprogramming you can do in zig or even C++ (which is also turing complete, just incomprehensible)
>However, most languages don’t share that philosophy, at least, not as strongly as Zig does.
Bryan Cantrill talked about values of different programming languages [1] and I think it's a particularly useful way to compare different languages and the choices they make when developing them.
It often seems that criticism that is directed at a language is simply a reflection of a difference in values.
1. https://corecursive.com/024-software-as-a-reflection-of-valu...
Zig-style generics are not well-suited for most languages - https://news.ycombinator.com/item?id=33142751 - Oct 2022 (128 comments)