8 ms·
Golang: How to Update APIs for Generics
- 37ef_ced3 5y agoThis is the way: Use new major versions for stdlib packages, e.g., sort/v2
- xyzzy_plugh 5y agoCertainly this is true, but I wouldn't put it past rsc & co to find some magical incantation that provides full backwards compatibility. In particular the alias keyword was quite succinct and not abused much.
- tikkabhuna 5y agoSounds like a nightmare for newbies getting started. If this is the way forward, and I agree its the most Go-like, I would like to see good support for warning users to use v2 and why they need to.
- YesThatTom2 5y agoQuite the opposite. Naive users will not be affected. They’ll just use generics and not realize that for certain types the code generated is more specific. Or are you assuming newbies read the standard library source?
- bradleyankrom 5y agoI know a lot of “get started with Go” blog posts, books, etc recommend going through the standard library code to see conventions in practice. Go’s stdlib is relatively easy to read, especially if the consumer has some previous experience with other languages.
- nirui 5y agoI don't think it would be that easy. Think how the maintainers of third-party package will maintain their package after this: before, they just need to target the one and only `atomic` (or any other package mentioned in the GitHub discussion), now they might have to target both `atomic` and `atomic/v2` just to support generics. I really hope they could come up a cleaner solution than this.
- blondin 5y agojust an aside but that github discussions feature looks amazing -- first time i am noticing it. so many "issues" are really just discussions. kudos to the github team.
- lerax 5y agoI agree, that is a great feature. Now we can separate what is a true project issue than a broad question/discussion
- icy 5y agoIt irks me that they have both votes and reactions.
- sk0g 5y agoYou can have a funny/ insightful comment that doesn't add to the discussion, so it makes sense to me at least. It's like Facebook + Reddit/ HN voting systems at once.
- vhanda 5y agoThe problem is that there is a convention of using :thumbs-up: for voting on an issue. Many people forget that discussions have their own voting mechanism, independent on reactions. Plus, when migrating an issue to a discussion, the reactions are transferred, but since people were using :thumbs-up: for voting, the new system isn't used for old issues turned discussions, and this whole thing becomes a mess.
- qaq 5y agoCan't wait for the thing to land. My only remaining wish is sum types
- rawoke083600 5y agoTHIS ! and "pattern-matching" :)
- a-saleh 5y agoSo, in the end all of languages move closer to StandardML :D Like even python has sum-types and pattern matching now!
- rawoke083600 5y agoLol I know I know... but it is so useful :)
- xmorse 5y agoThat would be awesome!
- tonyedgecombe 5y agoAnd exceptions :)
- szastamasta 5y agoPlease, just not exceptions.
- brabel 5y agoThey're still trying to decide basic stuff like how to transition existing APIs to generics!? Wow, that means it will be a long time for generics to land on stable Go.
- arghwhat 5y agoBecause it's far from basic stuff when you have to consider stability guarantees.
- pjmlp 5y agoYou know how to avoid those problems? By having them since the begining, it is not as other languages haven't gone through the path of bolting on generics after the fact, as an example for others to learn from.
- rubenv 5y agoI for one like not having things rushed in which then cannot be changed later on. Does this mean Go is perfect? Not at all. It just means I'd rather have generics late than fundamentally broken.
- pjmlp 5y agoFor the time we have waited already, what is a couple of years more, right? Now if that would have been part of Go 1.0....
- can3p 5y agoSo far I prefer this approach to any other. I know this type of discussion happens under any go submission, but still - need in generics is overrated, there a ton of code written for all sorts and purposes and scales and it works just fine. And all that without a gigantic marketing push which means that developers simply like it that way it is. Go is about compatibility, being able to control your code base and being confident about results and I'd really prefer them to take their time thinking through a non-critical feature rather then rushing it and exploring all sorts of unexpected side effects down the road.
- ddevault 5y agoThis is Go's Python 3 moment. This creates a hard fork of the ecosystem, with a before and after, and all existing Go code is now un-idiomatic and will have to be refactored, rewritten, or replaced.
- ngrilly 5y agoNot really. Python 3 introduced breaking changes requiring modification of your code base. That's absolutely not the case here for Go. You can still compile and run your code unchanged. You are also overestimating the magnitude of the number of line of codes impacted by the new style using generics.
- ddevault 5y agoIt's not a breaking change, but it is a radical change for what it means for Go programs to be Go programs. All Go programs are now written the "wrong" way. Or, in other words: all present Go programs would not pass a code review if they were introduced following the release of Go 2. This also affects many libraries throughout the ecosystem, increasing the API churn and burden on downstream projects. It will create millions of man-hours of work for Go users.
- pjmlp 5y agoThey will still compile with a Go 2.0 compiler, try to run a Python 2.7 script on Python 3.9.
- dpatterbee 5y agoEvery Go program written using interface{} to provide psuedo-generics was known to be "wrong" at the time it was written, unfortunately the "right" way wasn't a part of the language so people put up with it. I don't believe that generics are going to radically shift any facet of Go programming and I predict that a year from now they'll be just another feature of the language. If somebody's refactoring some area of code that heavily uses interface{} or code generation maybe they'll considered rewriting parts, but interface{} and code generation are not deprecated or made obsolete by generics.
- jcelerier 5y ago> I'm going to go out on a limb and suggest that we use the Of suffix for generic container types do people ever learn anything.. conventions don't work, only things checked by the language grammar matter
- tazjin 5y agoThis is explicitly the language for not learning things we've figured out over the last decades so ... no ;-)
- pjmlp 5y agoGiven that some of the language designers had the same approach for safety in C versus the existing alternatives, yep people don't learn much.
- SPBS 5y agoDoesn't matter, the standard library simply has to set a consistent example for people to follow. They can choose to ignore it.