Posted by vips7L 3 days ago
> Structs and classes can even overload this operator
nope. fuck, now it's a terrible idea
Vec2 result = translation + (rotationMatrix * (scalingMatrix * point));
Over this: const result = vec2Add(translation, mat2MulVec2(rotationMatrix, mat2MulVec2(scalingMatrix, point)));
AnytimeAnd that's a very simple example, in Zig, that kind of equations doesn't scale well, when it comes to readability
C# has "^n" notation that means "length - n". For example:
Take the last element of an array or any other structure that supports indices:
var a = ar[^1];
Take the last three elements of an array or any other data structure that supports ranges: var lastThree = ar[^3..];
You can also overload +, imagine the mayhem if someone did something weird with that. should we ban overloading operators altogether?
excuse me, have you spent any time in tech? people fucking love to do clever shit that gets people in trouble. using NULL as a not-pointer value signalling absence (without safeguards) is probably the most notorious -- but at least useful, but if you want to get brain meltingly annoying and pervasive, we dont have to stray too far from the idea of operator overloading; c++'s << operator can just go to hell.
I have yet to run into an instance where someone has overridden operators to do something completely insane. Honestly the weirdest real use-case I've ran into is pathlib overriding division on path objects to instead mean concatenation. Which seems confusing until you realize it just means paths get written like `build_dir = root_dir / "build"` which is sensible enough.
Weirdest not-real use case is of course the famous goto-in-python module which overrides attribute access in combination with unhinged dark magic to implement goto.
(come on, a low effort joke now and then is ok, if not for anything else, as an counter-example)