3 ms·
Is there a reason Go is not using <> instead of ()? So instead of func Print(type T)(s []T) { for _, v := range s { fmt.Print(v) } } we would get func P
by shp0ngle 6y ago
Is there a reason Go is not using <> instead of ()?
So instead of
func Print(type T)(s []T) {
for _, v := range s {
fmt.Print(v)
}
}
we would get
func Print<T>(s []T) {
for _, v := range s {
fmt.Print(v)
}
}
?
- shp0ngle 6y agooh they address it themselves in TFA https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md#why-not-use-the-syntax-like-c_and-java https://go.googlesource.com/proposal/+/refs/heads/master/des...
- masklinn 6y agoThe angle brackets increase parsing complexity because `>` is a valid standalone operator (which neither ] nor ) is, usually) making the grammar ambiguous: given Foo<Bar> You still don’t know whether this is a bunch of comparisons or a parametric type, meaning you need either feedback from the type checker into the parser or possibly unbounded lookahead before you can even generate a parse tree.
- st1ck 6y agoApart from other reasons, it just looks ugly. Any kind of braces is better than <>.