Basically, unlimited look-ahead.
This reduces the amount of state that the parser has to carry around and makes the error messages for syntax errors easier to generate.
Languages that use <>'s for generics have to look at a larger amount of the code when parsing to work out what to do.
"Resolving that requires effectively unbounded lookahead. In general we strive to keep the Go parser simple."
It's totally fair to question the tradeoff - should having a simple parser outweigh the potential ergonomic benefit of <>? I don't know. The forum for this is probably the golang-nuts group.
I think "simpler" would have been a stronger argument. While using <> would make the parser more complex, I have a hard time seeing that making a meaningful performance difference in a compilation context. Maybe if you're parsing a lot of Go without actually compiling it, but that doesn't seem like a use case to optimize for.
https://go.googlesource.com/proposal/+/refs/heads/master/des...
Hmmm ... not sure how I feel about that. Ok so my original example becomes this:
func (obj *SomeType) Foo(type K, V, Q comparable)(key K, val V) (*OtherType(Q, V), error) {
...
}
Which is only slightly better [without the generic type].Don't get me wrong, I'm a big fan of Go, but I'm kind of on the fence about generic types. I've made do with casting interfaces and type-casts for many years and I'm OK with it (honestly, glad to not be a C++ or Java programmer anymore).
No, you still don't understand. Methods can't have additional type parameters, only functions. This part is not allowed in your "example":
(type K, V, Q comparable)> Generic types can have methods. The receiver type of a method must declare the same number of type parameters as are declared in the receiver type's definition. They are declared without the type keyword or any constraint.
So my original example should have been:
func (obj *SomeType(K, V)) Foo(key K, val V) (*OtherType(K, V), error) {
...
}
(hopefully this is now correct!).
Also note that generic methods are not allowed in the current design, only generic functions.
The new draft design ( https://go.googlesource.com/proposal/+/refs/heads/master/des... ) discusses both of these points. I recommend everyone who is interested in this topic read the design spec, ideally before commenting.