Generic methods approved for Go, devs miss other features • The Register


The Go team has approved generic methods, reversing a longstanding position in the language’s FAQ. The proposal, from Go co-designer Robert Griesemer, now moves to implementation.

A key issue – that Go interfaces cannot include generics – will remain. The earlier view was that since generic methods cannot implement interfaces, there was no point in having them. Developers could simply code generic functions, which already exist. The change of view is that methods are useful for organizing code even if they do not implement an interface, so there is no reason not to have them support type parameters – generics – in the same way as functions.

Griesemer said that the new feature is fully backward-compatible with existing Go code, though tools will need to catch up. The interface issue remains, though, and Griesemer added that providing generic methods “doesn’t preclude the implementation of generic interface methods at some point, should we find an acceptable implementation solution.”

The first version of Go, released in 2012, did not support generic programming at all, though it was a common feature request. Go 1.18, released in March 2022, added generic features, with type parameters for function and type declarations. Even before this release, a request for generic methods attracted widespread support but was rejected on the grounds now referenced by Griesemer, that it was uncertain whether permitting generic methods to implement interfaces was “reasonably possible,” and that, in other cases, a parameterized function could be used.

Developer reaction to the approved proposal is positive, though many recognize that the feature is incomplete. “My internal utility library has a bunch of workarounds for missing generic methods and they all annoy the hell out of me,” said one. Another said that “it’s going to be somewhat confusing when it exists in this format because generic methods can’t be used to satisfy interfaces.”

In January, the Go team released the results of its 2025 developer survey, based on responses mainly from professional developers using Go as their primary language. While Go developers are generally satisfied with the language (91 percent), a top-three frustration is the lack of features that exist and are valued in other languages. Generic methods are one such feature, but there are bigger asks, including the lack of full-featured enums (enumerated types), lack of exception handling, and lack of nil pointer safety. One of the top-voted comments on Reddit sums it up: “Go got generic methods before enums. Crazy.”®



Source link