5 ms·
Operator overloading would be fine if everybody had some standard for how to employ it sensibly. Unfortunately, the C++ standard library (over)uses it poorly al
by Retra 11y ago
Operator overloading would be fine if everybody had some standard for how to employ it sensibly. Unfortunately, the C++ standard library (over)uses it poorly all over the place, so it's really not setting an example of moderation.
- conistonwater 11y agoThis is a common sentiment I think, but operator overloading, at least in the context of numerical analysis, has perfectly sensible standards already, as in Matlab, R, python, julia, and the like, yet C++ under-uses it and doesn't even provide anything overloadable for matrix-multiplication (like `.* ` vs `* `) or a linear solve `\` operator. C is even worse, since you can't even define arithmetic operators for a custom numerical type.
- Retra 11y agoThat's true if you're only looking at arithmetical operators. C++ most often overloads assignment and indexing operators. You can even overload the cast operator, and if that isn't confusing and unnecessary... just don't ever use std::vector<bool>.
- vinkelhake 11y agoAside from vector<bool>, which pretty much everyone agrees is a failed experiment, where do you think operator overloading overused in the standard library?
- Retra 11y agoIterators using ++ Write/Read using << and >>. Not a major problem, but it's weird and not very useful when you're trying to be C compatible. You can index into a std::deque, but not a std::queue. I'd also count the need for explicit in constructor declarations to be a similar kind of mistake.