7 ms·
In part I agree. If you have "a + b", and a and b are Employees, what does that even mean? Does it commute? Who knows? But "adding" strings specifically, th
by AnimalMuppet 6y ago
In part I agree. If you have "a + b", and a and b are Employees, what does that even mean? Does it commute? Who knows?
But "adding" strings specifically, that idiom is I think sufficiently well established that it's in the category of "know the language - you're not in C anymore".
I want operator overloading. I want to be able to use + for adding, say, quaternions with integer components modulo n. (I also like my operators.) I want to be able to use | for or of fuzzy booleans defined as reals on the closed interval [0, 1].
I don't want + for Employees. But given what I do want, I don't see how anything other than good taste can allow the one and prohibit the other.
- b2gills 6y agoI didn't realize that concatenating two strings was the same exact concept as adding two numbers together. You learn something new everyday. Oh, they're not? Then why are you using the same operator? ... They reused the operator because you can say in English that “you are adding two strings together”, and have it be a perfectly reasonable sentence to say. As the designers were English speaking, it made enough sense to them to add it to that operator. If they spoke a different language, who knows what operator they would have used instead. A better idea would be to allow people to add new operators. Even better if you can use that same feature to extend existing operators where it makes sense. The reason few languages allow that is that their parsing system is still largely designed around the memory and speed tradeoffs that were required in the 1970s. As such it is difficult to alter the parser while it is parsing. Raku has this feature, and it works by subclassing the current parser to add new operators. (It's intended that you can also temporarily replace it for one that parses an entirely different language.)