On 9/23/2013 9:51 AM, Jesse van den Kieboom wrote:
> I would like to announce a little project that I started to allow operator
> overloading in Go. go-operators is a tool which transforms Go sources such
> that operators on types are translated to corresponding method calls on
> those types if available. It basically converts a Go source to an AST using
> go/ast. Then, a patched version of go/types walks over the AST, and
> resolves operators (binary and unary) on normally unsupported types to
> method calls on those types, if possible.
>
> I don't want to start a discussion on whether or not operator overloading
> is a good idea. Personally, I'm happy that Go doesn't support operator
> overloading in the language in general, except for the case of writing some
> numerics code (which arguably you shouldn't with Go).
Go is potentially a good, fast language for numerics, and I've been
pushing for multidimensional arrays. But others have convinced
me that overloading operators in Go is a bad idea, even for math
operations.
I could become convinced that overloading + and - is a good
idea. But even * gets complex. Dot or cross product? What gets
called for vector * matrix? That's why NumPy uses X.dot(Y)
and X.cross(Y), but overloads + and -.
Overloading binary operators in a language that doesn't
support multiple argument overloading means you have to define
your own overloading semantics.
John Nagle