Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@snakeru
Last active August 16, 2019 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snakeru/aebc533b14a3f045f2bbb0d8eda5ed27 to your computer and use it in GitHub Desktop.
Save snakeru/aebc533b14a3f045f2bbb0d8eda5ed27 to your computer and use it in GitHub Desktop.
Go2 generics syntax simplification proposal.

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:

  1. (least confusing) The fact that a well-known keyword type appears in a function declaration
  2. The fact that using a generic type and defining a contract for it use different keywords that are seemingly independent (type vs contract)
  3. (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) { ... }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment