Hacker News new | ask | show | jobs
by stephc_int13 1859 days ago
My concern about zig/jai and others, is meta-programming.

Meta-programming can be super powerful and practical, and the current trend of reusing the language itself is clearly better than previous attempt.

But meta-programming in itself is not a novel idea, C macros and C++ templates are past well studied examples, and both produced awful results.

I am not sure they can prevent a new cycle of this nightmare.

3 comments

Maybe I am just a huge dummy, but I have yet to find examples of metaprogramming in the wild that aren't just mind-meltingly hard to grok. (Most of what I have seen is Python and Rust).

I have no doubt about how powerful metaprogramming is, but it makes me feel that understanding and contributing to libraries that use it is out of my reach.

I think what's novel about Zig's approach is that the metaprogramming is just normal code which happens to be executed at compile-time.

I have found that when any project gets to a certain size, it's almost inevitable that metaprogramming will be required, unless you want to make everything super dynamic and sacrifice performance. The idea of being able to do metaprogramming in the language I used to write the program itself is an interesting one.

I don't know if Kelley would agree with my characterization, but I don't see comptime as metaprogramming. Instead it opens the very interesting possibility of having types as values, as long as those values are resolvable at compile time. This lets you do things that feel like metaprogramming (e.g. making a generic container structure) but it seems a better conceptual fit to me that you're programming with types as values rather than generating code from a template or macro.
This is nothing novel. LISP macros is exactly that.
in fact i believe templates are the greatest idea in static typing. they look awful because its design and the implementation is awful not the idea. c++ failed because they didn't know and too late to turn back, and rust just looks same, you should see d-templates.
I think that templates can be practical and readable if used with moderation, just like macros.
> C++ templates are past well studied examples, and both produced awful results.

What's wrong with templates ? They give you a compile-time functional language that operates on types, isn't that great ?

Imagine being able to use C++ to operate on types at compile time instead of using the verbose template syntax.