Why doesn't Go have generic types

Open source: Go should have generic types

The programming language Go is to be expanded to include generic types. For this purpose, the participants have created a corresponding entry in the bug and issue tracker for the language on Github, as the team writes on its blog. Since Go was first announced in 2009, this function has been one of the most frequently requested language functions. After more than ten years of using the language, it could now be implemented.

  1. akf bank GmbH & Co KG, Wuppertal
  2. Simba Computer Systeme GmbH, Ostfildern (near Stuttgart), Karlsruhe, Oberhausen

The team presented the first concrete suggestions and arguments for implementation in a lecture at the Gophercon conference in summer 2019. The idea behind generics is to define certain functions or data structures generically and thus to abstract them from the basic data types available in language. For example, lists, including the algorithms required for sorting or the like, could be defined for an abstract data type, which is then filled in with the actual types when specifically called.

Such considerations hardly play a role in dynamically typed languages ​​such as Python or Javascript, since functions can be created without worrying about types. However, this does not work in statically typed languages. That's why C ++, Java, Rust and Swift Generics. This does not apply to Go so far, but this could change now.

From the language team's point of view, the problem with the implementation of Generics in Go was, according to their own statements, to find a design that blends in well with the language. After years of iterating the ideas, this has now happened and the proposal is good and simple enough to propose as an addition to the Go language.

Go - The practical book: Getting started with Go and the Go ecosystem
  1. PostgreSQL Fundamentals
    14.-17. September 2021, online
  2. Docker & Containers - From Zero to Hero
    June 15-17, 2021, online
Further IT training

Existing Go programs are not affected by the change and do not have to be adapted. Those involved hope to discuss the design proposal intensively with the rest of the community and to be able to implement it in the language in the medium term. As usual with Go, the goal is a consensus decision on the inclusion of generics. Although such a large change could not satisfy everyone, the team strives for a solution that is acceptable to everyone. If everything goes as planned, the generics could be introduced with the beta versions of Go 1.18 at the end of this year.