Mark Phelps markphelps.me

Trying out generics in Go  ↦

This is the first (of probably many) “playing with generics” post we’ll see now that Go 1.18 is in beta with official support for the controversial feature.

This post aims to describe my initial experience converting my markphelps/optional library from using code generation to using generics instead. Hopefully, after reading this post you’ll have a better understanding of what generics can do for you and what they can’t.

Mark shares lots of good tips along the way. His findings are quite positive:

I ❤️ that I was able to delete 95% of my code because of generics.

I think that generics will be very beneficial to maintainers who create libraries for things like my own as well as for searching, sorting, transformations, and the like. I can also see some them being extremely helpful for creating well-tested libraries around the various concurrency patterns that are sometimes tricky to get right.


Discussion

Sign in or Join to comment or subscribe

0:00 / 0:00