# Common pattern in other languages
max<int>(1, 2)
# Similar pattern in Go
#go:generate gofmt -r 'T -> int' -w max.go
max(1, 2)
But yes, "true" generics are much more complicated (and arguably impossible in Go without major changes to the language), I realize. A number of languages that even claim to have generics fall short on that front, which is a path the Go authors have said they do not want to go down.Although you do have me curious how you'd implement max in C in this type-safe way using standard tooling:
#define max(a, b) (a > b ? a : b)
...obviously wouldn't fit the bill since it doesn't enforce types like to Go version does.