What can be confusing is what the meaning of `+` (or `plus` is). In some case it can be fairly obvious (e.g. concatenating sequences), while in other not so much. Operator overloading is nice, but has to be used tastefully (like every abstraction or language tool).
What can be confusing is what the meaning of `+` (or `plus` is)
QED
Amazing, I know.
Also please actually read the comment before replying:
> Operator overloading is nice, but has to be used tastefully.
a := Sum (b, c)
How can you be sure that Sum actually does a sum without looking at its implementation?A concept used in lambda calculus, introduced in computing since Lisp exists.
Also part of abstract mathematics field, where operator symbols get defined for the proofs.
From a Go point of view, it isn't.
[1] - According to the language designers own words
It's not exactly magic.
In Go, it's impossible to tell because "a" might be captured by a closure, in which case it will be heap-allocated. But if escape analysis promoted it to the stack or a register, then it will not allocate memory.
Of course, you can go to the C extreme, no overloading, specialisation or anything, every function name means one thing. That does add some nice features, but is a pain in the ass when naming things!
Yes, this is a problem with many designs. More importantly they can't easily look up what does an operator do. But this problem can be easily avoided if a set of operators used in a particular scope had to be explicitly specified. For example, if you want "+" to mean a bigint addition from a set of bigint math operators, you would have to import that set into that scope, kind of like this:
import_operators "bigint"
a := b + c
Now you still have overloading, but it is very clear where to look up an operator and a set of operators used in this scope."In go there's only two possibilities for what this code is doing..."
There should be only one possibility, though. Dual-meaning operators don't provide any value to ever have them, apart from familiarity with design mistakes of the past.
That is overloading! What go eschews is user-defined overloading.
In C#, you can overload operators, so the + could in theory do anything. And what's bad about that is that it is deceptive. It's easy to miss the fact that this line might actually be doing something complex.
It also means that if someone is looking at your code, they can't make any assumptions about what any particular line of code is doing, without complete understanding of a vast amount of code.
This is one of the pieces of magic that I'm glad go doesn't have.