Hacker News new | ask | show | jobs
by baby 2516 days ago
I have two comments to make about this proposaL:

1. The type should indicate a generic, not a new syntax. This is better because it is easier to parse for the human eye. For example:

  func Reverse(first _T, second _T)
2. Since all of what generics are is a compile-time code generator, I suggest that Golang forces developers to explicitly list what types are using the generic:

  generics(Add) = {int, string, car, food}
  func Add(first _T, second _T)
This list can be added to, after importing the package:

  Import “thing”

  generics(thing.Add) += {stuff}
This makes code very explicit about its generic functions. It also allow readers to understand exactly where the function is used.