3 ms·
> They're just two different names for the same thing No, they are not. One is a function, the other is an operator. An operator has implicit meaning. I know
by usrbinbash 3y ago
> They're just two different names for the same thing
No, they are not. One is a function, the other is an operator.
An operator has implicit meaning. I know with absolute certainty, that `+` is supposed to mean that 2 things are added to one another.
`Add()` is a function. Its name may or may not indicate what it is actually doing. Even if it indicates it, it may not be obvious how it is doing it's thing, or how good the indication is. Example: If Add takes as first argument a list and as second argument an integer, does it append the integer to the list? Does it add it to every element of the list? Does it sum the list and add the integer to the result? All these things could be meant by "Add"-ing an integer to the list. Does it have side effects?
I don't know, and I don't expect to know, until I look at `Add()` (or at least read it's documentation).
That is the big difference between operators and functions; With operators, I expect to know what it does, without looking it up. And that's also the big problem with operator-overloading, because as soon as a language supports that, that assumption flies out the window.