Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Stovoy/8436904d0167cc282ea00449b0c75298 to your computer and use it in GitHub Desktop.
Save Stovoy/8436904d0167cc282ea00449b0c75298 to your computer and use it in GitHub Desktop.
I’ve just finished reading through the now approved proposal for generics in Go and am beyond excited.
Speaking as someone who works for a major tech company that uses primarily Go, and having personally been writing Go on-and-off for over 5 years, I believe this will be a huge game changer.
In particular, this will very strongly support and encourage companies to use Go for higher performance critical projects as opposed to C++ or Rust. Allow me to illustrate why I believe this to be the case.
I’m a big fan of Rust as well, and had attempted to introduce it at work in the past. It’s difficult to integrate, and the learning curve is a problem, as well as general complexity in comparison to the extreme ergonomics of Go.
Why Rust? Rust has no garbage collector, and is certainly faster than Go, due to having effectively no runtime. For real time computing, projects with extreme performance requirements, or with strict memory budgets, Rust will still be superior.
However, there’s a middle ground where Go will now be competitive, and most importantly, practical: applications where there exist highly optimized, yet complex, data structures. More advanced constructs such as lockfree data structures, graphs, and trees, will now be accessible to all Go code.
It’s true that you could utilize these already in Go, but without generics, it’s been very restricting for creating generalized data structure and algorithm libraries. These problems end up being solved ad-hoc, on a case-by-case basis. The wisdom of the crowd isn’t being utilized, and so less efficient solutions end up being the common case. Most projects would simply opt for a less performative, but simple solution.
This is what I believe is one of Rust’s strongest points. The availability of high-quality open source data structure libraries is incredible, and allows one to use highly optimized code without needing to write it from scratch. adding implementation complexity. C++ is similar in this regard.
With generics, not only could pure Go versions of such libraries be written, but there can even be generic wrappers around such libraries from other languages in cases where Go’s runtime was too heavy.
This is a huge game changer. It’s true that we could already do this kind of thing; writing extremely optimized Rust code and calling it from Go. That’s inarguably a big undertaking, adding a huge amount of technical investment. This complexity can now be moved out and pooled from the open source community.
Imagine! Well documented, easy to use, common libraries with high performance, that solve exactly the general problem you’re trying to solve.
From the other side, every engineer who builds a tuned, specialized algorithm or data structure is now able to generalize it and share it with the world, or within their team. It allows the ultimate level of code deduplication, on a community level.
In conclusion, I couldn’t be more excited for generics. It will extinguish it’s largest weakness, and bring a new wave of adoption for Go. Most of all, it’s just going to be plain fun and awesome to work with. I can’t wait.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment