![]() |
VOOZH | about |
We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.
Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.
Follow TNS on your favorite social media networks.
Become a TNS follower on LinkedIn.
Check out the latest featured and trending stories while you wait for your first TNS newsletter.
The debate around adding generics to the Go programming language has been going on for years now, often with much resistance, but it’s starting to look like one proposal finally has some backing and general acceptance from the greater Go community — much to the surprise of some involved.
Introduced this week in a blog post looking at the next step for generics, penned by Golang team members Ian Lance Taylor and Robert Griesemer, the first update in nearly a year on the topic explains that the generics design draft previously submitted for feedback has been refined, resulting in an updated design draft. The authors summarize the primary difference between the two proposals:
The biggest change is that we are dropping the idea of contracts. The difference between contracts and interface types was confusing, so we’re eliminating that difference. Type parameters are now constrained by interface types. Interface types are now permitted to include type lists, though only when used as constraints; in the previous design draft type lists were a feature of contracts. More complex cases will use a parameterized interface type.
For the time being, the team has introduced an experimentation tool that “permits people to type check and run code written using the version of generics described in the design draft” by translating generic code into ordinary Go code. It is meant to give users a feel of how the proposed design would, if accepted work, and they note that it will be implemented differently if so.
I’ve done over 1000 (mostly API design) reviews when I was working on Go. You might be wondering who needs generics, here are my three categories:
– Data layers, database APIs
– Collections
– Container typesLack of generics is not just copy/paste but causing error-prone APIs.
— Jaana Dogan (@rakyll) June 17, 2020
As for the proposal itself, it offers several levels of detail, from an abstract, to a high-level overview, to the full level of detail you might expect from such a document. As with everything Go, the design is intended to be fully backward compatible with Go 1, and the authors note that “as the term generic is widely used in the Go community, we will use it below as a shorthand to mean a function or type that takes type parameters. Don’t confuse the term generic as used in this design with the same term in other languages like C++, C#, Java, or Rust; they have similarities but are not the same.”
The team says that they are, as usual, looking for feedback from the Go community at large, with the best way being to use the golang-nuts@googlegroups.com mailing list. In this effort, they are looking to learn two primary things:
“First, does generic code make sense? Does it feel like Go? What surprises do people encounter? Are the error messages useful?
Second, we know that many people have said that Go needs generics, but we don’t necessarily know exactly what that means. Does this draft design address the problem in a useful way? If there is a problem that makes you think ‘I could solve this if Go had generics,’ can you solve the problem when using this tool?”
“Go is a toy language because there are no generics”
*Adds generics*
“Real languages use <T>”— Miek Gieben (@miekg) June 17, 2020
C programmers are like pic.twitter.com/8sREwhgVVh
— Graham Christensen (@grhmc) June 17, 2020
git push origin andtonic
— Leah Culver (@leahculver) June 17, 2020
remember logging off?
— Owen Williams ⚡ (@ow) June 16, 2020