Why generic builtins instead of a Channel interface?
Why is len a function and not a method?
We debated this issue but decided implementing len and friends as functions was
fine in practice and didn't complicate questions about the interface (in the Go
type sense) of basic types.
Also worth noting is that debate happened in 2009 or earlier, which is 7 years ago. After that, Go 1 has been released with its promise/guarantee of compatibility [1], so changing the language is not possible. It is what is, and significant language changes can only happen in Go 2. Until then, many, many people and companies are using Go 1 with huge success and happiness and have built great things with it. In practice, I find it works really well.I guess there's a certain cleanliness whereby all methods exist on one side of the language/library dividing line.
† The sole exception perhaps being "error", which is a pre-declared interface comprising 1 method.
---
In a similar vein, this takes some getting used to:
x.append(y) # No!
append(x, y) # Probably Not!
x = append(x, y) # Yes! (but this is not Lisp - despite appearances, the collection is mutable)Ah! Beacause it is like Lisp?
(setf x (nconc x y))
I.e. the empty list cannot be mutated to non-empty, but non-empty can mutate to different non-empty.Surely, we could wrap append with a appendf (append functional), such that we can do:
x = appendf(x, y); # no mutation: original x preserved
Inside appendf we might have to do something gross, like duplicate the entire object, and append to the copy.Go was invented for internal Google use, and then shared with the world, and Google is an engineering company. If engineers would have rebelled, higher management probably would have done something about it.
-----
Although I don't understand why they keep fighting it. A simple style generics (Java style) shouldn't make code that ugly.
Not necessarily. Go was invented for internal Google use, but most of Google's code is still in C++ and Java. New projects are often started in C++ and Java, even, as they depend on libraries written in those languages. I think this would be true even if Go were perfect; switching languages is hard. But it means you shouldn't assume Google has solved whatever problems one would encounter while implementing Google product X in Go. Or that all Google engineers believe Go is a good language; as with any large group of programmers, there are people with opposing viewpoints about the virtues of various programming languages.
Google management doesn't tend to impose top-down technical decisions such "product team X must use Go" [1] or "the Go team must add language feature X". They generally give broad direction and then trust the engineers doing the work to find the best technical approach to accomplish the task.
[1] Although you generally must stay within the handful of approved languages: C++, Java, Go, JavaScript (for frontend stuff), Python (mostly for internal stuff, and getting less socially acceptable over time). One reason for this list is that when you write a Google system in a new language, you need a bunch of support from the rest of the company to do it: build infrastructure, libraries, etc.
Go was invented by a small group at Google with the aim of solving some of Google's problems as they saw them. It's not as if the whole of Google came together and collectively designed the language they needed. I wouldn't read too much into the fact that it happened to be invented at Google, rather than wherever else Rob Pike happened to be working at the time.
Java-style generics are a lot of things (notably “bolted on”), but “simple” certainly isn't one of them. Wildcards are complex. F-bounded polymorphism is complex. Non-denotable types are complex.
Variance is straightforward anyway. A lot of things in Go, like the semantics of "nil" and zero values, are more complex than variance. And, as a designer, if you're worried about the complexity, just make all type parameters invariant, like C++ does. It's a bad excuse to not have generics at all.
Rust works exactly the same way as Go (coercions, no subtyping), except that there is subtyping in Rust via the region system. But Go doesn't have that. No region system, no subtyping.
And I don't think making all type parameters invariant eliminates any complexity. It just pushes it onto the user.
Whether or not they are a show stopper for the users - well, that depends on your use case and preferences. Since show stoppers are a subjective thing. Objectively you could implement everything in Assembly or even Machine code, and people used to write rather complex programs this way.
I personally know there are a lot of types of systems I would never implement in Go if given the choice, because it would be too bothersome, and I don't like RSI. YMMV.
IIRC most of Google is C++ and Java, which both have generics.
I read somewhere that they have a lot (I think it was in the MLOC range) of proprietary/in-house code written in go.