Hacker News new | ask | show | jobs
by jesserayadkins2 3640 days ago
There's no operator overloading. I'm pretty reluctant to add it too, because I've seen it be abused far, far too many times. It has uses, yes, but I'm not very interested in it at the moment.

I won't say absolutely no to it, but if it were to be added, it wouldn't be right now. There's too much api that needs doing right now.

3 comments

I always dreamed of language without operator overloading, but with builtin vectors and matrices. Maybe they could be easily mapped to SIMD instructions. They can have a bit different operator (like in one PEP [1]).

I know that there are intrinsics for C, but they are non portable. Maybe except NaCl [2].

Also is concatenation of strings only done through usage of $"^(variable)" syntax?

[1] https://www.python.org/dev/peps/pep-0465/

[2] https://developer.chrome.com/native-client/reference/pnacl-c...

It's probably possible, especially with today's compilers being smarter about using those instructions. You're right, in that concat is currently only available through interpolation.

At the moment, I'm not interested in adding vectors or SIMD. It's something I might try further down the line, but not now.

That's a fair point but on the other hand I think operator overloading is a must to be able to program math formulas in a language. Do you plan to have something like `const` as well? If so, how about allowing operators, but only if they don't modify the object (though, that rules out stuff like+=).
Const is something that I'd like to think over before adding it. A question I have is what happens if a List is const, or should it just be that only primitives are const? I could see const values being optimized as just literals down under the hood, which would be nice for performance.

I'd have to have a long, long think before adding operator overloading. It's got uses for math, but thus far I've been reluctant to add features that can be abused or used improperly like native class dtors or finally.

Have you looked into the difference between c++ const and java final for an example of different semantics? Suffice it to say the two are very different. Not sure why anyone would be doing math code in an interpreted language, I guess if it where embedded in game engine that would be desirable, but then users may wrap c/c++ math libraries with swig-alike to use, using the ffi, whatever that turns out to be.
Can you give an example or two of abuse that you've seen?

I've seen the complaint that operater overloading allows abuse, but most the examples I've heard seem farfetched.