I would argue that support for inline operators for doing linear algebra (i.e. matrix/vector operations) is as natural as inline operators for integers/floating point numbers and it is crucial if golang is to gain traction in the scientific community. I was curios if there are any plans to ever add operator overloading to the language, even if just for matrices?
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
So basically, I feel you are proposing a language change that will complicate things just for ONE very special edge case - matrix algebra. My magic 8-ball says: "No, this will never happen".
--
I don't see how you could possibly add operator overloading to the language as it stands-- it doesn't even have method overloading... Would you want it to be something like this?type Matrix interface {func (m Matrix) Add(other Matrix) Matrixfunc (m Matrix) +(other Matrix) Matrix}
I would start to use Go for my next game TONIGHT but the thought of having to write something like:r:=a.Add( b.Scale(c).Sub(d) )Instead of:r:=a+(b*c-d)
sent from my droid
Sounds a lot like SymPy, Theano or any symbolic engine...
-s
>
>
> --
> - yiyus || JGL .
>
I have written Game and physics engine in Go (https://github.com/vova616/GarageEngine) and the main problem was not the syntatic suga but the performance.I had to inline huge amount of code to pure math and the performance boost was huge. (ex: p = Add(s,v) to p.x, p.y = s.x+v.x, s.y+v.y and etc)
If we implemented everything people miss when using Go, we would end up back at square one with C++.
While working on a missile simulation project at Boeing, I had to translate, code, and optimize mathmatical formulas and algorithms into java code for the better part of four months. While I would have loved to have written code that more closely resembled the math I was using, writing unit tests amd fast iterations was the most important factors. I'd surmise that because math is easy to test and verify, the significance of native feeling syntax is of lesser importance. It also helps that those are the parts of the systems, that once coded, typically can be left alone.
There's a quote from Clean Code - write your code in the solution domain, not the problem domain. Operator overloading tries to keep the code too close to the problem domain. Code is not math, despite what some people may say. If you want to fill a page of code with math equations, you're doing it wrong. Yes, at some point you'll probably have to do a dot product of a couple vectors, but it should be limited to a small function with very few lines, which is used by more generic functions, and can be easily tested. We should be producing packages that help abstract away the details of the math so that you can solve the problem, not solve the math. Trying to duplicate math in Go simply perpetuates the problem... everyone has to solve the math over and over, rather than solving the problem.
--