3 ms·
except are you sure that's what it's doing? it could have been overloaded. you have to ask yourself that every time.
by throwawaymaths 1y ago
except are you sure that's what it's doing? it could have been overloaded. you have to ask yourself that every time.
- Doxin 1y agoOr you can assume it's implemented sanely. Yes if someone overrides $ and does something wildly wrong with it that'll get confusing. That's the fault of whoever wrote that code though, not of $ itself. You can also overload +, imagine the mayhem if someone did something weird with that. should we ban overloading operators altogether?
- throwawaymaths 1y ago> Or you can assume it's implemented sanely 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.
- Doxin 1y agoI work in tech full time. I mostly write python code. Python similar to D allows you to override ~all operators. 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.
- 1980phipsi 1y agoI've looked at a lot of D code, and I can't recall it ever being misused.