Making code-generation in Go more powerful with generics
The article discusses the use of generics and code generation in Go programming language. It explains that generic programming allows writing algorithms with unknown parameters or return types, which can be instantiated when needed for specific types provided as parameters. The author shares their experience at incident.io where they combined generics with code generation to provide useful developer flows and solve some tricky pain points in their codebase. They introduced the concept of partial structs using generics, which represents a subset of a whole struct type and tracks which struct fields it sets. This approach helps in performing safe, partial updates in database records. The author also talks about code generation helpers around Partial types, such as builders and matchers, to improve the experience of using Partials. Overall, the combination of generics and code generation provides a balance between developer experience and runtime safety.
Company
Incident.io
Date published
Oct. 20, 2022
Author(s)
Isaac Seymour
Word count
1991
Hacker News points
5
Language
English