6 ms·
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 tha
by felixgallo 3y ago
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.
- jsheard 3y agoThere's no accounting for taste, but the two major publicly available engines (Unreal and Unity) both use operator overloading in their standard math types.
- Taywee 3y agoYou'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.
- flohofwoe 3y agoFWIW Zig can do that without operator overloading: https://www.godbolt.org/z/7zbxnncv6 https://www.godbolt.org/z/7zbxnncv6
- kprotty 3y agoVectors in Zig are SIMD types. Vectors in games are probably algebraic types. Using SIMD for the latter may not be that useful if 1) specific elements are accessed frequently 2) transformations involve a different operation happen on each element.
- cyber_kinetist 3y agoFirst 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.
- felixgallo 3y agoI have a marvelous proof that you can solve that with comptime but unfortunately the margins of this website are too small to contain it.
- lvass 3y agoDo us a pastebin, please.
- QQ00 3y agoYou can use pastebin, or even better, use github gist.
- another2another 3y agoI think you have briefly deluded yourself with an irretrievable idea.
- chlorion 3y ago>That's some spooky action at a distance nonsense. In pretty much all languages operators are just sugar for calling a method. There is no difference other than an easier to read syntax. In rust for example, doing a + b is exactly the same as doing a.add(b). In python it's exactly the same as doing a.__add__(b). In C++, my understanding is that its sugar for a.operator+(b) or operator+(a, b). I think there are some arguments against operator overloading but "spooky action at a distance" doesn't seem to be a very good one to me.