3 ms·
> 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
by naikrovek 4y ago
> 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.
- cycomanic 4y agoBut 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?
- Kukumber 4y agoi'm not asking for operator _overloading_, i am asking for having operators for my math types
- renox 4y agoGood point, you could have + * / restricted to basic types, but have #* #+ #mod_add as (overloadable) operators.
- adgjlsfhk1 4y agoreadability 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.
- WalterBright 4y agoHere's a sweet example of proper use of operator overloading: https://dlang.org/phobos/std_checkedint.html 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)));
- Symmetry 4y agoI 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.
- masklinn 4y ago> 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.
- deleted 4y ago[deleted]
- skocznymroczny 4y agoIt 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.