News for hackers. Stuff that matters.
Re:Why Go Is Not Good (2014) by fixermark on Wednesday December 09, 2015 @10:50AM (#10704290)
"Go does not support operator overloading or keyword extensibility."

Very much working as intended, I believe. Experience from languages that support those features has shown that what we gain in the very few situations where those extensions make sense (such as defining mathematical operations on vectors using the same symbols that are used in vector mathematics), we lose in too many developers thinking they have a clever shortcut that an existing operator would be perfect for, to the detriment of readability and comprehensibility.

This is also the era of code-analysis-by-search-engine, and operator overloading harms that feature significantly. If I need to find all instances of vector addition in my code and I'm searching for '+', I'm going to have a bad time.

Re:Why Go Is Not Good (2014) by coldpie on Wednesday December 09, 2015 @11:06AM (#10704437)
This is a well-written objection and I completely agree. Operator overloading is consistently one of the worst ideas I see in programming languages, C++ being the prime offender. Programmers think they're being clever when they write crap like

  boostfs::path path("/some/path");
  path /= "yourfile.txt";
Meanwhile, reading your code without being familiar with boostfs::path, my brain grinds to a halt while I try to understand what in the hell dividing by a string is supposed to do.

This is one of those "well intentioned" features that turns into a quagmire in practice.

Re:Why Go Is Not Good (2014) by masklinn on Wednesday December 09, 2015 @11:18AM (#10704537)
> Operator overloading is consistently one of the worst ideas I see in programming languages

Except when not having it is the worst. Working with BigDecimal in Java is hell because it does not have operative overloading, meaning while you avoid

    boostfs::path path("/some/path");
    path /= "yourfile.txt";
you get saddled with bullshit like

    x.add(x.add(ONE).pow(2).subtract(x))
Re:Why Go Is Not Good (2014) by exDM69 on Wednesday December 09, 2015 @12:43PM (#10705239)
Now this is ugly:

    x.add(x.add(ONE).pow(2).subtract(x))
Especially because sometimes it is difficult to decide whether you should have x.foo(y) or y.foo(x). However,

    add(x, sub(pow(add(x, ONE), 2), x))
Is perfectly acceptable in my opinion (add some indentation if it's difficult to read). As long as you can pass parameters and return values without tricks (ie. passing pointers), this is quite nice. You should even be able to do this in Java with "import static". Or C++ with function overloading.

I'm definitely not a fan of C++ -style operator overloading, where you only have a finite amount of operators with set precedence/associativity and then they get overloaded to meanings that the symbols don't convey. On the other hand, I'm not sure what to think of Haskell either (where you can define arbitrary operators, like >>=, <+> or <$>). It's not as limited as C++, but there are some quite nasty examples that have gone overboard with operators.

Overall, it seems like operator overloading adds a lot of complexity to a language but the benefit is arguable.

Re:Why Go Is Not Good (2014) by eveningcoffee on Wednesday December 09, 2015 @01:02PM (#10705429)
However

I comletelly agree with this, it is very confusing API.

You should even be able to do this in Java with "import static"

Yep, you should define a static methods add, sub, pow etc with BigDecimal parameters and then use import static.

Something along

class BigDecimalMath { public static BigDecimal add(BigDecimal x1, BigDecimal x2) { return x1.add(x2); } }

Also JVM JIT would very likely inline such code, so you should not really worry about an added method call.

Re:Why Go Is Not Good (2014) by kilink on Wednesday December 09, 2015 @02:08PM (#10705954)
Too bad you can't just call functional interfaces in Java 8, or you could just do something like this:

BiFunction<BigDecimal, BigDecimal, BigDecimal> add = BigDecimal::add; add(x, y);

Unfortunately you have to do:

add.apply(x, y);

Which is kind of cumbersome.

Re:Why Go Is Not Good (2014) by eveningcoffee on Wednesday December 09, 2015 @02:34PM (#10706128)
Yes, it pretty much defeats the point. It would work if they had implemented a default method for an interface.

Unfortunately they brought something completely different in the name of Default Methods, and that was in my opinion not needed.

Re:Why Go Is Not Good (2014) by coldpie on Wednesday December 09, 2015 @11:21AM (#10704554)
Eh, there's already no language symbols for exponentiation (unless you're really going to overload XOR in which case you're already part of the problem).
Re:Why Go Is Not Good (2014) by pcwalton on Wednesday December 09, 2015 @11:33AM (#10704671)

    func SameSideOfTriangle<N>(p0 Point2D<N>, p1 Point2D<N>, a Point2D<N>, b Point2D<N>) bool where N: Number {
        ba := Point2D(b.x.Sub(a.x), b.y.Sub(a.y))
        p0a := Point2D(p0.x.Sub(a.x), p0.y.Sub(a.y))
        p1a := Point2D(p1.x.Sub(a.x), p1.y.Sub(a.y))
        cp0 := ba.x.Mul(p0a.y).Sub(p0a.x.Mul(ba.y))
        cp1 := ba.x.Mul(p1a.y).Sub(p1a.x.Mul(ba.y))
        dot := cp0.x.Mul(cp1.x).Add(cp0.y.Mul(cp1.y))
        return dot >= 0
    }
Versus:

    func SameSideOfTriangle<N>(p0 Point2D<N>, p1 Point2D<N>, a Point2D<N>, b Point2D<N>) bool where N: Number {
        ba := Point2D(b.x - a.x, b.y - a.y)
        p0a := Point2D(p0.x - a.x, p0.y - a.y)
        p1a := Point2D(p1.x - a.x, p1.y - a.y)
        cp0 := ba.x * p0a.y - p0a.x * ba.y
        cp1 := ba.x * p1a.y - p1a.x * ba.y
        dot := cp0.x * cp1.x + cp0.y * cp1.y
        return dot >= 0
    }
Re:Why Go Is Not Good (2014) by coldpie on Wednesday December 09, 2015 @11:42AM (#10704752)
I didn't mean to imply that it is never useful, just that it's not worth the baggage in my experience.

Genuinely asking: Why does this function need to be generic over Numbers? Couldn't you implement it once or twice for whatever actually-numeric types you need? How many different Point2D template instantiations do you actually have?

Re:Why Go Is Not Good (2014) by pcwalton on Wednesday December 09, 2015 @11:53AM (#10704865)
In my project, i32, u32, f32, and f64. Possibly others.

And that's only a small function (only one part of what's needed to check point-triangle intersection!) Copying and pasting e.g. Sutherland-Hodgman clipping or 4D/5D matrix math would get unsustainable quickly.

Re:Why Go Is Not Good (2014) by fixermark on Wednesday December 09, 2015 @11:51AM (#10704834)
My experience from graphics programming is that, yes, this is a subdomain where you want both the ability to shorten your functions with overloading and the ability to make your underlying types dynamic. There's a lot of fiddly-bit optimization in that space that is both necessary and much easier to do if you can transition quickly and smoothly from one type to another without having to boil an ocean of declarations.

Granted, you then have the problem of having to deal with overflow on different types, but that's just one of the ocean liner of problems you've signed up for if you're working in the graphics space. May the odds be ever in your favor. ;)

Re:Why Go Is Not Good (2014) by masklinn on Wednesday December 09, 2015 @11:24AM (#10704581)
`.pow` is the least problematic part of my example by a fairly long shot. Even keeping it, with operator overloading you'd get

    x + ((x + ONE).pow(2) - x)
or

    x + (pow(x + ONE) - x)
Re:Why Go Is Not Good (2014) by blub on Wednesday December 09, 2015 @11:38AM (#10704711)
Yes, boost has a couple of instances of eyebrow-raising uses of operator overloading. Including stream operators, that still does not prove that operator overloading is an anti-feature.

On the contrary, when all you have is a couple of examples that aren't even that bad and a slippery slope argument, you are on very thin ground, rhetorically speaking.

Re:Why Go Is Not Good (2014) by coldpie on Wednesday December 09, 2015 @11:44AM (#10704774)
It's clearly a balancing-act thing. My scales tip to the hater side.
Re:Why Go Is Not Good (2014) by alextgordon on Wednesday December 09, 2015 @12:19PM (#10705053)
I am certain that if you did some game programming in a language without OO, you would quickly change your mind.
Re:Why Go Is Not Good (2014) by maemilius on Wednesday December 09, 2015 @11:32AM (#10704657)
It's funny. I know very little about C++ and my first thought was that this was, essentially, a shortcut for something like:

    path += '/' + 'yourfile.txt';
It's also entirely possible that I'd already subconsciously read ahead and so knew that it couldn't have possibly been division.
Re:Why Go Is Not Good (2014) by coldpie on Wednesday December 09, 2015 @11:34AM (#10704681)
It's easy in a little two-line snippet discovered in the context of a discussion about operator overloading. It's much less easy to understand when grepping for a config file name (which is where I found it) where you don't even have the declaration of the variable to give you the context that you're dealing with anything other than char*.
Re:Why Go Is Not Good (2014) by ltbarcly3 on Wednesday December 09, 2015 @11:02AM (#10704403)
>> Experience from languages that support those features has shown that what we gain in the very few situations where those extensions make sense

Nope, this is just incorrect. The C++ is completely dominant in large swaths of the software industry largely because operator overloading allows the writing of generic algorithms (which allows you to write large scale software without losing C-like performance). Without operator overloading, it is much harder to write a function that can be specialized on types that weren't specifically designed for such use.

In Python, Numpy, the Decimal class, I could really give examples for days of cases where operator overloading is essential. Go doesn't have it, Go doesn't have a lot of things, and Go will always be an also-ran language that isn't adopted outside of a very narrow domain.

The fact that built in types are 'special' and only they can support operators such as [] is enough for me to avoid the language. The complete lack of generic programming is more than enough.

Re:Why Go Is Not Good (2014) by tptacek on Wednesday December 09, 2015 @11:07AM (#10704448)
Could you go into more detail about why operator overloading enables generic functions in a way simple functions don't? I don't see it.
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.
Re:Why Go Is Not Good (2014) by justin_vanw on Wednesday December 09, 2015 @11:08AM (#10704455)
Because you would have to come up with a naming convention ahead of time.
Re:Why Go Is Not Good (2014) by tptacek on Wednesday December 09, 2015 @11:13AM (#10704497)
And you're suggesting that nowhere in what used to be called the C++ Standard Template Library is there a place where they didn't have to come up with a naming convention for functions?

I think you may have the causality swapped here; I think <algorithm> looks the way it does because they limited themselves to things that could be easily expressed with operators --- for a long time, to the detriment of the language; see: STL associative containers, operator<, and the longstanding lack of a standard hash table.

Re:Why Go Is Not Good (2014) by blub on Wednesday December 09, 2015 @12:19PM (#10705052)
How was <algorithm> preventing the introduction of a hash table? The hash function is a template parameter, predefined for standard types, no operator needed.

Josuttis claims that hash tables didn't make it in C++98 due to lack of time.

Re:Why Go Is Not Good (2014) by fixermark on Wednesday December 09, 2015 @11:05AM (#10704434)
I think we're talking about different things. Can you give an example of how operator overloading improves one's ability to write a function that can be specialized on types that weren't specifically designed for such use?
Re:Why Go Is Not Good (2014) by justin_vanw on Wednesday December 09, 2015 @11:11AM (#10704477)
Type 1 defines: .add(x)

Type 2 defines: .plus(x)

Type 3 defines: .vector_add(x)

Now, implement a function 'average' that can work on any of these three types.

If you can get everyone in the world to agree to a convention of how to express 'addition', then there is no difference, except we already have a convention for 500 years, and it is the '+' operator. Why you think the '+' operator is confusing but .plus() is not, that is what confuses me.

Or how about 'minimum'. In C people end up writing a minimum C macro, because there's not even a way to write one function that works on int, long, float! What a sad world that is, where you have to meta program to implement min(x,y).

Re:Why Go Is Not Good (2014) by jerf on Wednesday December 09, 2015 @11:28AM (#10704616)
Operator overloading is often problematic because the operators come with semantic baggage, such as properties they maintain, and implementations of those operators often don't maintain those properties. For instance, addition is associative, and has no additional side effects beyond the value it produces, but an overloaded operator won't necessarily implement those. Abstractly there's nothing wrong with that, but in reality it has proved difficult. Operators also often come with an order-of-operation hierarchy designed for mathematical operations that map poorly or confusingly to what the overloaded operator is doing, which causes further practical mismatch.

Operator overloading works best when being used in domains where the original constraints hold; for instance, adding a matrix to a matrix is mostly the same as adding two numbers, though if your type system can't enforce that the matrices are the same size at compile time, you still added the ability for + to throw an exception, which it will never do with ints. Operator overloading got its bad name from cases where people were overloading the operators to do something entirely unlike what the original operator did, causing a mismatch between the user's expectations and what it actually did and therefore bugs.

Operator overloading isn't really "right" or "wrong" per se, but it's probably a bad idea for anything that isn't able to fully implement the contract of the operator, including "associativity", "no side effects", whether exceptions can be thrown, etc.

If you read carefully, you'll generally see operator overloading arguments have two groups talking past each other, one cursing things like C++ streams that basically overloaded the operators in a meaningless way for nominal convenience that causes a lot of long-term headaches, and the other praising the benefits of overloading for math, since math is the big case where it works correctly.

Back on topic, Go correctly does not have operator overloading because Go's authors, as near as I can tell, have no intention of Go being good for mathematics.

Re:Why Go Is Not Good (2014) by kllrnohj on Wednesday December 09, 2015 @11:53AM (#10704862)
> Operator overloading isn't really "right" or "wrong" per se, but it's probably a bad idea for anything that isn't able to fully implement the contract of the operator, including "associativity", "no side effects", whether exceptions can be thrown, etc.

Operators are not special here. What you are saying is basically "don't claim to implement the interface if you didn't implement it".

This exact problem exists widely in, for example, Java. How often do you see a Java object where someone overrode equals() but not hashCode()? I've seen that problem vastly more often than anyone doing something crazy with operators.

Re:Why Go Is Not Good (2014) by masklinn on Wednesday December 09, 2015 @11:43AM (#10704765)
> you still added the ability for + to throw an exception, which it will never do with ints.

Not quite true, the language could implement checked over- or under-flows (I believe Swift does)

Re:Why Go Is Not Good (2014) by jerf on Wednesday December 09, 2015 @12:31PM (#10705141)
"Not quite true, the language could implement checked over- or under-flows (I believe Swift does)"

I am one of the apparently about ten people who thinks that should be the universal default. The vast bulk of people disagree, and I was trying not to poke the sleeping dog. :)

Re:Why Go Is Not Good (2014) by masklinn on Wednesday December 09, 2015 @01:07PM (#10705483)
> I am one of the apparently about ten people who thinks that should be the universal default.

There's a handful of us, a handful!

FWIW Rust checks for overflow in debug mode, and while that's elided by default when compiling with optimisations it can be re-enabled with a -Z flag:

    > rustc test.rs
    > ./test
    thread '<main>' panicked at 'arithmetic operation overflowed', test.rs:4
    > rustc -O test.rs
    > ./test
    Overflowed!
    > rustc -O -Z force-overflow-checks=on test.rs
    > ./test
    thread '<main>' panicked at 'arithmetic operation overflowed', test.rs:4
And of course some languages bypass the whole thing by automatically promoting to dynamically sized integrals.
Re:Why Go Is Not Good (2014) by jerf on Wednesday December 09, 2015 @03:41PM (#10706574)
Well, that's that then; now I just need a Rust project and I'll start learning it. (I'm only an early adopter of languages, not a bleeding-edge adopter.)
Re:Why Go Is Not Good (2014) by Gankro on Wednesday December 09, 2015 @02:54PM (#10706249)
"everything is floats" is also technically a solution, but with a curious fail-state.
Re:Why Go Is Not Good (2014) by fixermark on Wednesday December 09, 2015 @11:19AM (#10704538)
Ah, I see what you mean. You can see this issue in action in Go's math package, where "Min" is defined on only float64.

I was lumping this in under the general category of the "Go has no generics" issue; without generics, Go can't do this anyway (and the closest solution you would have would be to define an interface Algebraic that specifies functions algebraic types need to support, then implement operations like min and average atop those interfaces). I'm still of the personal opinion that (as other commenters noted) what you gain in being able to define operator+ you lose in boost developers getting clever and implementing operator/= on paths; even if we had generics, I'd personally find a Go-like solution of declaring the function package an algebraic type had to support (via an Interface) preferable.

Re:Why Go Is Not Good (2014) by gendoikari on Wednesday December 09, 2015 @11:28AM (#10704618)
I think that if you begin with the idea that you have multiple conventions and you cannot avoid that, therefore you won't solve the problem with "+" operator. You have just one more convention. Type 1 defines: .add(x), Type 2 defines: .plus(x), Type 3 defines: operator+, ... If you assume that you can convince people to adopt a convention, you can use .add(x) and avoid the problem in the first place. Go for example tries to have always one obvious way to write things. The Go standard library it's the idiomatic Go bible.
Re:Why Go Is Not Good (2014) by coldpie on Wednesday December 09, 2015 @11:18AM (#10704534)
> Now, implement a function 'average' that can work on any of these three types.

I'm not convinced this is such a large problem that its solution is worth the myriad downsides that operator overloading is chained to. There's lots of schoolbook examples like this, but I've almost never seen operator overloading used well in practice. There's a few examples, like boost shared pointers are somewhat easier to read, but they're few and far between

Re:Why Go Is Not Good (2014) by pcwalton on Wednesday December 09, 2015 @11:24AM (#10704582)
> There's lots of schoolbook examples like this, but I've almost never seen operator overloading used well in practice.

I do graphics programming and I literally rely on it all the time.

Re:Why Go Is Not Good (2014) by woah on Wednesday December 09, 2015 @12:15PM (#10705025)
As someone above was mentioning, I don't think that go was ever intended for heavy math programming. It's a great language for writing network applications that is more performant and deployable than scripting languages, yet easier to use than low level languages. Use rust or c.
Re:Why Go Is Not Good (2014) by kllrnohj on Wednesday December 09, 2015 @11:57AM (#10704882)
Please elaborate on the myriad of downsides that operator overloading is chained to. I am honestly not aware of any downsides that are unique to operator overloading

Hint: Things like "they can be abused" or "you can do crazy things like have + return a dot product" are not unique to operators. I can very easily define .clone() in Java to return a dot product as well, or have .equals() do in-place addition.

Re:Why Go Is Not Good (2014) by innerspirit on Wednesday December 09, 2015 @11:18AM (#10704536)
At this point, operator overloading would simply be another convention, would it not? Your type would not work with mine if I used .add instead. You did not solve the problem of having to get everyone to agree on a convention.
Re:Why Go Is Not Good (2014) by gohrt on Wednesday December 09, 2015 @11:20AM (#10704548)
operator overloading is just overriding a base class (interface), plus a special and aribtrary limited syntax, plus compiler optimizations.
Re:Why Go Is Not Good (2014) by pcwalton on Wednesday December 09, 2015 @11:01AM (#10704400)
> If I need to find all instances of vector addition in my code and I'm searching for '+', I'm going to have a bad time.

This is true of methods too. If you're searching for vector addition and you grep for "Add()", you're also going to have a bad time. To have a reliable code indexing scheme, you need typechecking/name resolution information, and once you have that you can easily handle operator overloading as well.

Re:Why Go Is Not Good (2014) by fixermark on Wednesday December 09, 2015 @11:07AM (#10704449)
The difference is that "Add" is not a term that many search engines will drop on the floor. When you get out of the range of plain ASCII strings, you're leaving the range of symbols you can assume your tool of choice will be indexing into search for you.

This is likely a short-term reality, but it's the current reality.

Re:Why Go Is Not Good (2014) by pcwalton on Wednesday December 09, 2015 @11:26AM (#10704597)
How many code indexing tools are in use that aren't grep/ack/ag (because you can grep for +) and don't do semantic analysis? I can't think of any. Visual Studio, DXR (what I've used), all documentation tools, etc. can all handle overloaded operators, and have been able to for years. (Hasn't Visual Studio been able to index overloaded operators for, like, at least a decade?)
Re:Why Go Is Not Good (2014) by fixermark on Wednesday December 09, 2015 @11:40AM (#10704726)
github.com
Re:Why Go Is Not Good (2014) by pcwalton on Wednesday December 09, 2015 @11:46AM (#10704795)
That's fair.

Though I've always found GitHub's code search to be less than useful in general. I think it doesn't really make sense to not have overloading because GitHub doesn't support semantic indexing in 2015, especially since you can easily just not use GitHub for code search.

Re:Why Go Is Not Good (2014) by 15155 on Wednesday December 09, 2015 @12:42PM (#10705233)
GitHub search breaks on really simple things, too:

- Queries <= 3 characters in length

- Certain common characters are totally not supported in queries - quotes, etc.

- Forks cannot be searched.

I always just clone and use a proper search tool if I know what I am looking for is in a specific codebase.

Re:Why Go Is Not Good (2014) by habitue on Wednesday December 09, 2015 @12:52PM (#10705329)
The way Haskell and rust solve this is that they constrain the types of the overload. If you want to overload +, you implement the Add trait, which has to be a certain type. The Add trait is googleable, and it provides a hint as to how the operator is to be used. In practice Rust and Haskell have much less of a problem than C++ in this respect. Additionally, having a strong culture helps (which Go obviously does). Python has no restrictions on overloading, but it's much less abused than in C++ because there's a cultural aversion to making operators do crazy stuff
Re:Why Go Is Not Good (2014) by cmrdporcupine on Wednesday December 09, 2015 @10:53AM (#10704319)
I agree that operator overloading is probably a feature not wanted in a language with this target problem domain.

However "working as intended" I think is also the response of Go to their lack-of-generics, which I think is kind of crap.

Re:Why Go Is Not Good (2014) by gendoikari on Wednesday December 09, 2015 @11:01AM (#10704397)
About generics, this is highly debatable. This is a design choice, it's not a decision made by accident. You'll surely gonna have boilerplate code in some cases, but all the language will be a lot more readable, and simple. Simplicity it's the most wanted feature of Go, from the designers perspective, I think. In the long term it's preferable to have explicit and simple code, instead of complex magic. This is a correct view? We'll see. Honestly I'm starting to appreciate that. They may have a good point.
Re:Why Go Is Not Good (2014) by mercurial on Wednesday December 09, 2015 @11:24AM (#10704586)
How is code with generics more complex than without it?
Re:Why Go Is Not Good (2014) by gendoikari on Wednesday December 09, 2015 @02:34PM (#10706132)
For example the C++ templates rules are themselves a turing-complete language. If by generics you meant some really basic features, I think you can do pretty well with interfaces. They're already in the language. If by generics you meant the full-package, i think you could end up with something pretty complex all the time.
Re:Why Go Is Not Good (2014) by mercurial on Wednesday December 09, 2015 @03:49PM (#10706642)
Most generic implementations are not Turing-complete, and looking at C++, this doesn't sound like a particularly tempting proposition.

And while I'm not particularly familiar with Go, I don't see how you can get a feature set equivalent to a simple implementation like Java's out of Go interfaces ("you can just cast" is not a good answer).

Re:Why Go Is Not Good (2014) by gendoikari on Wednesday December 09, 2015 @05:58PM (#10707441)
I'm probably missing the use case. What is the problem that you are thinking of, you can't solve with a Go interface?
Re:Why Go Is Not Good (2014) by mercurial on Thursday December 10, 2015 @12:24AM (#10709045)
Say, a generic container.
Re:Why Go Is Not Good (2014) by rbjorklin on Wednesday December 09, 2015 @01:57PM (#10705881)
They're talking about the compiler and the language spec not Go code.
Re:Why Go Is Not Good (2014) by mercurial on Wednesday December 09, 2015 @03:45PM (#10706606)
That's not how I interpret parent's comment.
Re:Why Go Is Not Good (2014) by TuringTest on Wednesday December 09, 2015 @11:27AM (#10704604)
> all the language will be a lot more readable, and simple. Simplicity it's the most wanted feature of Go

This is what Java designers thought as well. See where this has led them.

Re:Why Go Is Not Good (2014) by moultano on Wednesday December 09, 2015 @11:56AM (#10704879)
Without generics, you can never write a type safe datastructure. I can't imagine the hubris that thinks the language already contains all of the datastructures it needs.
Re:Why Go Is Not Good (2014) by kyledj on Wednesday December 09, 2015 @12:24PM (#10705094)
This isn't true. You can write a type safe data structure. It is simply for one type; you can't share it. That inability to share is the part that generics fixes, but saying you can't write type safe structures is inaccurate.
[deleted]
Re:Why Go Is Not Good (2014) by 15155 on Wednesday December 09, 2015 @12:43PM (#10705241)
> to keep the language spec and compiler simple

How is this not a design choice?

Re:Why Go Is Not Good (2014) by ghthor on Wednesday December 09, 2015 @12:50PM (#10705298)
Yea, You are right, guess it's to early in the morning for me to be responding to others. =D
Re:Why Go Is Not Good (2014) by omginternets on Wednesday December 09, 2015 @11:03AM (#10704419)
>I think is also the response of Go to their lack-of-generics, which I think is kind of crap.

The response I've overwhelmingly observed from qualified voices isn't "boo generics!" but "generics are terribly difficult to get right, and we want to know more about Go's niche before making any design decisions in that realm".

I suspect you're reading a lot of drivel from web programmers who discovered net/http last Thursday. It's hard not to be frustrated with the internet, I concede...

Re:Why Go Is Not Good (2014) by TillE on Wednesday December 09, 2015 @11:22AM (#10704565)
A huge variety of other languages have successfully implemented generics. The Go team seems to be looking for some mythical ideal solution with no tradeoffs, and will therefore never do it.
Re:Why Go Is Not Good (2014) by omginternets on Wednesday December 09, 2015 @11:47AM (#10704804)
>A huge variety of other languages have successfully implemented generics

Completely irrelevant; the argument isn't "generics are hard [full stop]". The argument is "generics are hard" AND "we don't know Go's niche well enough to commit to any specific approach".

Re:Why Go Is Not Good (2014) by mike_hearn on Wednesday December 09, 2015 @12:27PM (#10705113)
But how can they not know that, after so many years?
Re:Why Go Is Not Good (2014) by omginternets on Wednesday December 09, 2015 @02:40PM (#10706162)
You'd have to ask them, but I suppose it takes years to carve out a niche.

What I can say is that I recently interviewed a Google engineer who was conducting a survey of Go's usage, so it seems they're at least studying the question.

Re:Why Go Is Not Good (2014) by thegeekpirate on Wednesday December 09, 2015 @12:50PM (#10705294)
> However "working as intended" I think is also the response of Go to their lack-of-generics, which I think is kind of crap.

Where the hell did you get that from?

https://news.ycombinator.com/item?id=9622417

Re:Why Go Is Not Good (2014) by BinaryIdiot on Wednesday December 09, 2015 @01:47PM (#10705806)
While I think your point about using them improperly is good (I know I've seen some weird shit back in the day I did C++) I still think there is merit to allowing operator overloading. Many times you may create units that should work when added together but need unique logic to make it happen and that just can't happen in GO today (you have to make an add() method or something similar).

So I think operator overloading can be exploited pretty horribly but can also make code far more intuitive. It's certainly not something that can't be worked around but I always err on the side of letting it happen and the community can direct people to using them most properly.

Re:Why Go Is Not Good (2014) by necessity on Wednesday December 09, 2015 @10:59AM (#10704379)
Agreed. Explicit is better than implicit in this case (and most, if not all, cases).
Re:Why Go Is Not Good (2014) by masklinn on Wednesday December 09, 2015 @11:47AM (#10704803)
Operators are no more or less explicit than functions or methods. "+" and "Add" are just as explicit.

A difference is that operators tend to have semantic baggage, which can be a huge boon when using operator overloading for e.g. calculations. C++ has demonstrated that it was a very bad idea to overload operator against their semantic baggage, but the lesson to draw from it is "don't do that" not "operator overloading is the devil".