All Topics
All Topics
Technology
Technology
Design
Design
Programming
Programming
Science
Science
News
News
Gaming
Gaming
Entertainment
Entertainment
Business
Business
Finance
Finance
Sports
Sports
Health
Health
Food
Food
Travel
Travel
Art
Art
Music
Music
Books
Books
Education
Education
Politics
Politics
Personal
Personal
No algorithm. No AI slop. No ads. Just RSS. Pro-human. Indie writers. Real journalism. Open web. Chronological. Hand toasted.

Proposal: Adding Generic Methods to the Go Programming Language

By

griesemer

4d ago· 10 min readenCode

Summary

This article proposes adding generic methods to Go, which would allow methods to declare their own type parameters (not just inherit them from a generic receiver type). Currently, Go supports generic functions but not generic methods. The proposal argues that this limitation is artificial and that allowing methods to have their own type parameters would make Go more expressive and consistent. The author presents a change of perspective on how methods are defined in the language specification, suggesting that the syntactic restriction preventing methods from being generic should be removed.

Key quotes

· 3 pulled
Per the current spec, a concrete method is a function with a receiver. Syntactically this is not quite true: while functions can be generic, methods cannot.
For clarity, in the following we use the term concrete method (or just method when the context is clear) to describe a non-interface method declared like a function but with a receiver.
A change of view.
Snippet from the RSS feed
Proposal: Generic Methods for Go A change of view. Background For clarity, in the following we use the term concrete method (or just method when the context is clear) to describe a non-interface me...

You might also wanna read