Hello, I’m fried fish.
Go1.18 beta1 was released just two days ago, and it will be two months before the official release of Go1.18 becomes available for production.
I’ve been collecting some information on generics, and in 2015 someone wrote on Hacker News, “Go 1.5 Max Procs Default,” teasing that Go doesn’t support generics for “political” reasons…
Read or some significance, and now the basic point of contradiction is consistent, so share to everyone.
netizen
@Aikah thinks the Go team is unlikely to include generics in the language, which is clearly a political issue rather than a technical one. The same goes for error handling.
Like many others, the user felt that Go did not strike the right balance between minimalism and functionality. Generics opponents favor the exchange of compile-time type checking (always safe) for run-time type assertions (which may fail).
They refused to acknowledge the fact. This is their argument against generics, and will ultimately undermine any potential growth of the language. They are basically acting against their own interests.
The official reply
Russ Cox has a formal reply: Sorry, but no: Generics is a technical issue, not a political one.
The Go team is not against generics per se, just against doing things that are not well understood or don’t work well with Go.
That’s the core point, the contradiction, that’s been going on since 2009.
Problems that will be encountered
The Go team felt that there were deep technical issues that had to be addressed in order to integrate the concept of generics into Go and work well with the rest of the system, and we didn’t have the answers.
I wrote a blog post on these issues a few years ago called The Generic Dilemma:
Even if you overcome the problems on that page, there are other problems, and the next problem you’ll encounter is “how to get programmers to omit type comments in a useful and easily interpreted way.”
That is, how to express the type parameters of generics more humanly and easily.
Generic example
For example, C++ allows you to write make_pair(1, “foo”) instead of make_pair
(1, “foo”).
To achieve this effect, infering the logic behind annotations requires pages and pages of specification, which is not a particularly easy programming model to understand, nor can the compiler easily interpret when things go wrong.
After this there must be more new problems in this.
Communicate with an expert
The Go team talked to some real Java generics experts, and each of them said much the same thing: Be very careful, it’s not as easy as it looks, and you’ll get stuck with all the mistakes you make.
As a Java demonstration, you can browse through most of Java Generics FaqS-Frequently Asked Questions:
See how long it takes you to start thinking, “Is this really the best way?” .
There are many problems encountered in generics, such as How Do I Decrypt Enum
:
For this reason, the Go team is cautious in its push for generics.
Admit shortcomings
The Go team is very clear and acknowledges the fact that there are certain disadvantages to not having generics.
You can either use interface{} to dispense with compile-time checking, or write code generators to complicate your build process.
Generics implemented in existing languages also have definite drawbacks, and there is one very big benefit to not compromising today: it makes it easier to adopt a better solution tomorrow.
conclusion
Today I share with you all the controversies and discussions about Go generics in the foreign community in the past, but the core point of generics is clear: “The Go team is not against generics per se.”
I have not been able to do generics, also because of a lot of concerns, do generics and Go parts, to solve a lot of deep problems, but also to solve the type parameter readability and other issues. That’s why it’s been delayed until now.
Back in 2022, it was all right. The community is ripping off multiple associated components behind generics, generic readability and structure…
Obviously generics are a double-edged sword, right? What do you think?
If you have any questions, welcome feedback and communication in the comments section. The best relationship is mutual achievement. Your praise is the biggest motivation for the creation of fried fish, thank you for your support.
This article is constantly updated. You can read it on wechat by searching “Brain into fried fish”. GitHub github.com/eddycjy/blo… Already included, learning Go language can see Go learning map and route, welcome Star urged more.