Generic programming for statically typed languages is a tool for building maintainable software. Generics have a lot of advantages and can create infi

Intro to Generics in Go: Type Parameters, Type Inference and Constraints

submited by
Style Pass
2022-01-25 07:00:07

Generic programming for statically typed languages is a tool for building maintainable software. Generics have a lot of advantages and can create infinitely reusable code, they do however, have a history of being overused and misunderstood leading to anti-patterns1. Due to the regularity of misuse the Go team has been reluctant to add generics to the language.

Beginning in February 2022, Go will introduce generics support in its 1.18 release2. The Go team spent many years researching and experimenting with different implementations of generics and their implications for Go. The Go team believes they have found an implementation that is both effective and, more importantly, maintains the simplicity of the language.3

One of the first concerns raised by engineers (back in 20094, before the first release of Go) about the Go language was the lack of generics support. For many years5 the community has been asking for generics and, for many years, there has been pushback from the Go language team.

Generics may well be added at some point. We don’t feel an urgency for them, although we understand some programmers do. - Originally posted to the Go FAQ

Leave a Comment