Hacker News new | past | comments | ask | show | jobs | submit login

There are many reasons. They are personal more than mistakes in Zig.

* I don't like how compile-time code can be mixed with runtime code. The idea is nice otherwise, but it confuses me.

* I spent a long time trying to understand Zig's async ([1]) and came away with more questions.

* I don't like the async model in general; I prefer structured concurrency. I think this is a mistake in Zig.

* The Zig community has put me off, though some of that is my own fault.

This is just a sample. I've written more other places, but I don't have access or can't remember where right now.

[1]: https://gavinhoward.com/2022/04/i-believe-zig-has-function-c...




I'd argue that compile-time is really nice exactly because it can be mixed with runtime. It takes some time to get a good grip of it, but in the end I realized that a lot of code can actually be made comptime.

I agree that async is peculiar, but I think it is still too early to decide if this works or not.


I agree that Zig's comptime can work for people like yourself. Nothing wrong with that.

I feel bad that my brain doesn't work with it.


Compile-time evaluation is easier if you think of it as a separate language for pre-computing and generating zig code where most of the time it's used to supply the type of a parameter or construct a container like you would with a template.

You have copy-paste operators like `inline for`, `inline while`, and `switch (x) { inline else => {} }` that focus on generating code given a value known at compile-time (think of it like running a C program to print out the code within a `for` loop then inlining that in your code) and are great when you need to unroll a loop or loop over the fields of a struct (e.g when printing it). If you find those difficult then try printing the code they inline to get a feel for how it changes your program or writing what they'd inline manually.

For the more template style `ArrayList(T)` style you can follow the logic yourself by writing the struct it would result in when you substitute the parameters (again a copy paste but with slightly more going on) and any more calls with the same parameters will always return the same struct back.

Branching at compile-time is like having a smarter `#ifdef` for the most part where you use `if`, `switch`, and other control-flow to decide which code should remain in the program as long as the condition is known at compile-time. This logic can be applied to the copy-paste operators too depending on the condition.

Async is very experimental and not complete so it's currently difficult for most. It can be thought of as a fancy way of creating a state machine with `.nextState()` being the `resume` keyword making it not a function but by having the compiler perform a little magic at compile-time it's possible to write code which doesn't care about this until you get to function pointers as then the difference starts to matter. If you want a C equivalent have a look at https://c9x.me/articles/gthreads/intro.html which covers it pretty well and it's almost what zig does for you with the `suspend` and `resume` keywords. `async` and `await` should be understood in terms of `suspend` and `resume` as they exist at a much higher level and can be a bit tricky. Another way to get a quick overview of what it's doing is to have a look at generators in python with `yield` and their equivalent with writing the state machine yourself as a class as it's equivalent.

If you feel like trying it again, don't be afraid to reach out on the zig room on matrix. I'll be happy to help with comptime and related things as it can be a bit difficult to grasp.

Oh and don't give up! The best parts about learning is the rewarding feeling when it finally clicks after all the hard work.


I know the technique of considering it a separate language. It doesn't work for me, unfortunately.

Thank you for the offer, but Zig really doesn't fit my brain. Nothing against Zig, either.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: