3 ms·
>No operator overloading means, among other things, no custom numeric-like types – including wrapper types for units (e.g. Feet) unless the language provides se
by coldtea 8y ago
>No operator overloading means, among other things, no custom numeric-like types – including wrapper types for units (e.g. Feet) unless the language provides separate support for those (e.g. Go does, Zig seemingly doesn't).
Most languages survived without that.
- dagenix 8y agoPrior to their invention, most drivers survived without airbags in their cars too. comex just noted that the design decision here has some tradeoffs. One of those tradeoffs is that you can't define wrapper types for units. Such a feature has clear use cases - it's not hard to find instances where unit conversion bugs have had severe consequences. "Most languages survived without that" is not a constructive comment.
- dullgiulio 8y agoThat's not what parent said. You can express your maths as function calls. Operator overloading is often misused and violates the principle of minimal surprise. You could even have side effects. Still, type safety is totally possible. In Go, of your unit is Feet, you wrap your int into Feet and you cannot sum it with anything but feet. And that's all compile time, no cost.
- dagenix 8y agoRegardless of if comex's comment was fully accurate, I was mostly responding to "Most languages survived without that" which isn't productive.
- coldtea 8y agoIt's not just some historical curiosity from privative computing days. Huge successful current languages don't have operator overloading now either. If anything, outside numerical/scientific work, it's even frowned upon. And even in languages that do have them, it's not like people usually work with typed feet and such units. It is indeed safer, but I'm not sure it's mainstream (F#, Ada, Rebol, etc). Of course one can find such typed unit libs for other languages with Op. Overloading (C++ eg. has boost.units), but it's not like they're mainstream even where Operator Overloading is available. In any case, it's not the first argument to make against a system language that it doesn't support Op. Overloading as a means for this use case.