←back to thread

Zig is hard but worth it

(ratfactor.com)
401 points signa11 | 5 comments | | HN request time: 0s | source
Show context
jsheard ◴[] No.36150389[source]
I get what Zig is going for in making all operations as explicit as possible, but I fear that it's going to turn away fields like graphics and game development where it would be a good fit except for the lack of operator overloading forcing you to go back to C-style math function spaghetti. It's all fun and games until what should be a straightforward math expression turns into 8 nested function calls.
replies(8): >>36150475 #>>36150541 #>>36150795 #>>36150946 #>>36151013 #>>36151746 #>>36151792 #>>36152172 #
bodge5000 ◴[] No.36150475[source]
I'm no expert on zig, but the one area I have seen it shooting up in popularity is game dev. Though I guess that is largely as a replacement for C, so "C-style" wouldnt be much of a concern
replies(3): >>36150560 #>>36150748 #>>36151102 #
jsheard ◴[] No.36150560[source]
Zig looks like a fine C replacement, but C isn't what people are using to make games in the vast majority of cases. It's all C++, and operator overloading is part of the "sane subset" that everyone uses even if they hate the excesses of modern C++ as a whole.
replies(1): >>36150721 #
felixgallo ◴[] No.36150721[source]
as a long time game dev, I actively don't want operator overloading. That's some spooky action at a distance nonsense. I'm not sure I have seen a codebase that involved operator overloading, either, and I've worked in or near a good quantity of well-known titles.
replies(3): >>36150843 #>>36151267 #>>36160066 #
Taywee ◴[] No.36151267[source]
You'd rather use explicit function calls for all linear algebra and geometry operations? I don't think adding two vectors using an overloaded + is that spooky or distant.
replies(1): >>36152896 #
flohofwoe ◴[] No.36152896[source]
FWIW Zig can do that without operator overloading: https://www.godbolt.org/z/7zbxnncv6
replies(2): >>36154682 #>>36154931 #
1. cyber_kinetist ◴[] No.36154931[source]
First of all that only works with vectors, but I want operator overloading to also work on things like matrices or custom types (for example quaterions, or a symmat3 struct that represents a symmetric 3x3 matrix using only 6 floats).

Additionally, for efficient math code you often want vector / matrix types in AOSOA fasion: for example Vec3<Float8> to store an AVX lane for each X/Y/Z component. I want vector/matrix operations to work on SIMD lanes, not just for scalar types, and Zig currently can't support math operators on these kinds of types.

replies(1): >>36155544 #
2. felixgallo ◴[] No.36155544[source]
I have a marvelous proof that you can solve that with comptime but unfortunately the margins of this website are too small to contain it.
replies(3): >>36156503 #>>36161875 #>>36165689 #
3. lvass ◴[] No.36156503[source]
Do us a pastebin, please.
4. QQ00 ◴[] No.36161875[source]
You can use pastebin, or even better, use github gist.
5. another2another ◴[] No.36165689[source]
I think you have briefly deluded yourself with an irretrievable idea.