This is feedback about "Why Generics?" blog entry (Ian Lance Taylor, 31 July 2019). I hope you find it useful.
As a long-time Go user, but a person who only now discovered that there is an ongoing generics effort in Go I find the following three aspects confusing:
- (least confusing) The fact that a well-known keyword
type
appears in a function declaration - The fact that using a generic type and defining a contract for it use different keywords that are seemingly independent (
type
vscontract
) - (most confusing) The fact that the word order in defining and using a generic type is different:
type Graph (type Node, Edge G)
vs contract G(Node, Edge)
(note G taking the last and not-so-last position).
I think these three problems could be solved by using the keyword contract
in all places and slightly changing the syntax:
contract Node, Edge G {...}
type Graph (contract Node, Edge G) struct { ... }
func New (contract Node, Edge G) (nodes []Node) *Graph(Node, Edge) { ... }