News for hackers. Stuff that matters.
Re:Zig, the Small Language by naikrovek on Wednesday September 07, 2022 @01:09PM (#32753298)
> if we can do 1 + 1, we should be able to do vec2 + vec2, same with mat4 * mat4

why? operator overloading doesn't help you solve any problems. you can have the readability with methods which are named appropriately.

operator overloading seems so powerful and useful until you realize one day that it only changes the appearance of things, and makes no difference whatsoever to anything you are actually doing.

Re:Zig, the Small Language by WalterBright on Wednesday September 07, 2022 @01:21PM (#32753433)
Here's a sweet example of proper use of operator overloading:

https://dlang.org/phobos/std_checkedint.html

where operator overloading is used to create variations on integer types, like specifying the behavior when overflow happens.

Besides, `a + b / (c * d)` is far more readable than `add(a, div(b, mul(c, d)));

Re:Zig, the Small Language by Symmetry on Wednesday September 07, 2022 @03:03PM (#32754947)
I think haskell does this right. You can make function infix by turning "add a b" into "a `add` b" and you can't overload existing operators but you can make your own and do "a _+ b" or whatever and everybody will know it isn't the standard + but it's still readable.
Re:Zig, the Small Language by masklinn on Wednesday September 07, 2022 @03:27PM (#32755431)
> you can't overload existing operators

You can though, just implement the relevant typeclass.

Not only that, but you can straight up shadow existing operators.

Re:Zig, the Small Language by skocznymroczny on Wednesday September 07, 2022 @02:25PM (#32754287)
It makes a massive difference. I find most math related code unreadable without operator overloading, such code is very common in e.g. gamedev.

Just because people misuse operator overloading doesn't mean it should be removed from the language.

Re:Zig, the Small Language by cycomanic on Wednesday September 07, 2022 @02:35PM (#32754438)
But we are using operator overloading already, + does work for the basic numeric types doesn't it? So why should the line be drawn at float or double (zig didn't have a complex type last I looked), why not vec?
Re:Zig, the Small Language by adgjlsfhk1 on Wednesday September 07, 2022 @01:18PM (#32753409)
readability is important. specifically, operator overloading is great because it makes code look more like math. when translating from math to code, this is highly useful.
Re:Zig, the Small Language by Kukumber on Wednesday September 07, 2022 @01:17PM (#32753399)
i'm not asking for operator _overloading_, i am asking for having operators for my math types
Re:Zig, the Small Language by renox on Wednesday September 07, 2022 @03:11PM (#32755112)
Good point, you could have + * / restricted to basic types, but have #* #+ #mod_add as (overloadable) operators.