Rejoice, long at last, all you Gophers, for the question of whether or not the Go programming language will adopt generics has finally, after many years of debate, been answered this week with the acceptance of a proposal made last month.
In this most recent proposal, Golang team member Ian Lance Taylor writes that generics have been “one of the most commonly requested language features” since the language was first released in 2009, but even then, it’s adoption doesn’t come without concerns. Taylor explains the idea of generics in the intro of his proposal:
“Generics can give us powerful building blocks that let us share code and build programs more easily. Generic programming means writing functions and data structures where some types are left to be specified later. For example, you can write a function that operates on a slice of some arbitrary data type, where the actual data type is only specified when the function is called. Or, you can define a data structure that stores values of any type, where the actual type to be stored is specified when you create an instance of the data structure.”
It is precisely this value proposition — being able to write reusable code — that excites some developers and has been behind the push all along.
Adding generics to Golang fixes one of the major things that annoys me about the language! I’ve written a bunch of Go code, and the amount of duplicate / boilerplate code this will eliminate will make it more enjoyable to use.
— Rob (@robdaemon) February 10, 2021
While we don’t need to relitigate the various arguments against adopting generics, now that a proposal has finally made it through the proposal process, a new concern has found its voice among several users: that when presented with a hammer, everything looks like a nail.
This aptly summarizes how I feel about Go generics, as we prepare to be reamed by oodles of “just because you can doesn’t mean you should” generic code.
In baking a code pie, generics should be the salt, not the sugar, but I have concerns about those getting mixed up.🧂💥😵 https://t.co/cQv3YQeqAM
— ian molee (@ianfoo) February 11, 2021
This wouldn’t be the first time, however, that a new language feature was confronted with this fear. When channels were introduced to the language, they too became the feature that, for a time, turned everything into a nail. As time went on, this concern faded, and the hope now is that the same will come to pass with the adoption of generics.
Yeah I brought this concern up with the Go maintainers during the review period and their response (which I agree with) was: you can write really bad code with channels, but the community has done a good job figuring that out. Generics hopefully will be the same.
— Mitchell Hashimoto (@mitchellh) February 11, 2021
Only time will tell, and for now, there is still some time left before all you Gophers will be able to get your paws on the long-awaited feature. At least according to the original proposal, the goal “will be to have a complete, though perhaps not fully optimized, implementation for people to try by the end of the year, perhaps as part of the Go 1.18 betas.”
Now, before moving on to the rest of the world of what’s happening in programming this past week, here’s a video looking at the potential paradigm shifts coming to programming, what with the advent of cloud native everything, in the years ahead.
This Week in Programming
- Is Pattern Matching a Step too Far for Python? Generics wasn’t the only controversial programming language addition this week, with the Python Steering Council making the decision to accept a number of Python Enhancement Proposals (PEPs) collectively known as the Pattern Matching PEPs. “We acknowledge that Pattern Matching is an extensive change to Python and that reaching consensus across the entire community is close to impossible,” the council writes, saying that, nonetheless, they “are confident that Pattern Matching as specified in PEP 634, et al, will be a great addition to the Python language.” One dissenter to the addition found their way to the pages of iProgrammer, with the snarky headline “Python Adopts Pattern Matching — Kitchen Sink Next.” While they “don’t think that pattern matching is a bad thing to add to Python,” they see its addition as part of a greater narrative of feature bloat. “It seems to be a non-essential with only minor advantages,” they write. “It does fit in with the life-cycle of a language, however: first its small, compact and lovable; then it adds the parts that a lot of programmers have been missing; then it adds the rest, including the kitchen sink, and settles to a bloated old age waiting for a new compact and simple language to replace it.”
Before kubernetes: I had lots of fires.
After kubernetes: I had horizontally autoscaling fires
— fraq (@0xfraq) February 9, 2021
- Google Ups Its Python Support: In other Python news, Google has offered an update around its support for the Python ecosystem, noting that the language is “critically important” to both Google Cloud and its customers, serving as a runtime for Google App Engine and Cloud Functions, among other internal uses. Presently, the company says it will increase its support for the Python Software Foundation with “a donation of more than $350,000 to support three specific PSF projects, with a focus on improving the supply-chain security of the Python ecosystem,” which include productionized malware detection for the Python Package Index, improvements for foundational Python tools and services, and a CPython Developer-in-Residence for 2021, who will work full time to help the CPython project prioritize maintenance and address its backlog. Google also says it will continue its in-kind donation of Google Cloud infrastructure to the foundation, and make the Google Cloud Public Datasets program the new home of a new public dataset of PyPI download statistics and PyPI project metadata.
British Python devs be like “that’s a constructor, __init__?”.
— Jesslyn 🇮🇩 (@jtannady) February 10, 2021
- The Rust Foundation Is Born: In some other big programming language news this week, the Rust Foundation officially launched earlier this week, with Amazon Web Services, Huawei, Google, Microsoft, and Mozilla committing to two years of “a more than million dollar yearly budget to develop services, programs, and events that will support the Rust project maintainers in building the best possible Rust.” As we’ve previously detailed, the Rust team found itself a bit upended last year when Mozilla, the company originally behind the open source language, laid off 250 employees, many of them Rust contributors. Now, six months later, the foundation is a reality and the future of Rust appears to be ensured. As previously explained in a FAQ about the foundation, the Rust Foundation will center its efforts more around handling legal issues, outreach, hosting infrastructure, and generally supporting the community than directing the future of the language itself. To that end, Mozilla has already handed off all trademark and infrastructure assets, including the crates.io package registry to the foundation, and a new board has formed with five board directors from the five founding member companies and five directors from Rust project leadership.
- Google Opens up Its 2021 Season of Docs: Finally, if you happen to be part of an open source software project and in need of help writing documentation, Google has announced that it is now accepting applications for organizations for its Season of Docs 2021, a program created to do just that. Last year, the project had 64 successful standard-length technical writing projects, with 44 documentation projects the year before. This year’s efforts “will continue to support better documentation in open source and provide opportunities for skilled technical writers to gain open source experience” and applications for organizations are open now until March 26, at 18:00 UTC. For technical writers interested in getting involved, there is a guide available and any questions regarding the program can be sent to email@example.com.
I’m glad Go is finally getting generics because my insurance wouldn’t cover brand-name Go. https://t.co/0NKnI9naJF
— Aaron Patterson (@tenderlove) February 10, 2021
Amazon Web Services is a sponsor of The New Stack.