News for hackers. Stuff that matters.
Re:Why Go Is Not Good (2014) by pcwalton on Wednesday December 09, 2015 @11:20AM (#10704549)
Without operator overloading, it's hard to make generic numeric algorithms palatable.

Compare (fake Go-with-Swift-generics syntax):

    func Distance<N>(x N, y N) N where N Number {
        return x.Mul(x).Add(y.Mul(y)).Sqrt()
    }
Versus:

    func Distance<N>(x N, y N) N where N Number {
        return Sqrt(x * x + y * y)
    }
If your reaction is "well, Distance doesn't look too bad like that", I can replace it with matrix multiplication or point-inside-triangle testing. Not having overloading quickly fails to scale.
Re:Why Go Is Not Good (2014) by howeman on Wednesday December 09, 2015 @11:50AM (#10704824)
Of course, you frequently don't want operator overloading for matrix multiplication. Avoiding allocations is a big deal for speed, and so c.Mul(a,b) is often the right answer even with operator overloading.
Re:Why Go Is Not Good (2014) by grayclhn on Wednesday December 09, 2015 @12:35PM (#10705180)
I'm not aware of a language that allows operator overloading for matrix operations, but denies you access to c.Mul(a,b) or the equivalent when you need it. I find operator overloading pretty crucial for prototyping this sort of algorithm even if I'm later going to refactor it for performance.

edit: rereading the earlier comments, this may be orthogonal to the GP's claim that operator overloading is crucial for generics. Ooops. :)

Re:Why Go Is Not Good (2014) by pcwalton on Wednesday December 09, 2015 @11:51AM (#10704835)
How does allocation relate to operator overloading?
Re:Why Go Is Not Good (2014) by tptacek on Wednesday December 09, 2015 @12:06PM (#10704958)
It gives you more explicit control over the storage being used for expression evaluation.
Re:Why Go Is Not Good (2014) by pcwalton on Wednesday December 09, 2015 @02:24PM (#10706057)
Can you give an example? I don't understand.
Re:Why Go Is Not Good (2014) by eatonphil on Wednesday December 09, 2015 @11:25AM (#10704594)
Wouldn't breaking it down into components instead of using a one liner be an appropriate response for readability's sake?
Re:Why Go Is Not Good (2014) by pcwalton on Wednesday December 09, 2015 @11:35AM (#10704692)
For the distance formula? That's about the simplest graphics routine in the world. If you can't readably write distance without temporaries, the language isn't really usable for (generic) graphics programming. Replace distance with bilerp or point-triangle intersection tests (as I did in a sibling comment) and you'll see what I mean.

(It's totally fine for a language to be not interested in that domain. But that doesn't mean operator overloading is bad. Overloaded operators are essential for some domains.)

Re:Why Go Is Not Good (2014) by bluefox on Wednesday December 09, 2015 @02:02PM (#10705909)
Actually your distance implementation is a good example of needless stuffing of expressions into a single function.

Many times you don't care for the (costly) square root, so a distance-squared function can be useful.

Multiplying x by itself ("squaring") can also be a useful function that is used a lot.

    (defun distance (x y) (sqrt (distance-squared x y)))
    (defun distance-squared (x y) (+ (square x) (square y)))
    (defun square (x) (* x x))
In the same way that we can decompose our code, we can also decompose the concept of "operator overloading": it gives you is the ability to use one-letter (1), fixed-arity and precedence-following (P), infix (I), operators for your own or someone else's operations (G).

In languages that support 1PI properties, you'd often overlook such decompositions because it's quick and easy to write sqrt(x * x + y * y). To read it, also, but then you find yourself doing more and more complex calculations in-line. Reading suffers. You may end up with something that's worse than the corresponding code in a language that encourages defining small functions instead. (Lisp, of course, lets you use any combination of these properties, but the latter style is the one normally used.)

Yes, this is a Go thread... but I'll leave it here anyway.

Re:Why Go Is Not Good (2014) by eatonphil on Wednesday December 09, 2015 @11:46AM (#10704790)
That's true. We had to write our own (generic) GLM library in university. Definitely wouldn't want to be doing that in Go.