Earlier quoted context omitted.
Maybe that's the issue. From what I have seen, the lack of generics mainly becomes painful when working in the numerical space. If I work on mapping JSON, doing APIs and CLIs I don't really need generics. If I work on algorithms and data bags then it starts to be annoying re-implementing the same thing over and over again. So in these discussion you have devops-type people mainly dealing with APIs that are perfectly…
I think you're exactly right: People who live and breathe JSON and strings don't (and probably shouldn't) care about use cases where the choice between float or double matters... I also see this with graphics people who live and breathe small (2x2, 3x3, and 4x4) matrices don't care about "type level integers" (as Rust calls them) to make 6x9 matrices efficiently live on the stack or in an array. > Is it possible that…
Notes on the Go2 Generics Draft
101–110 of 116 posts
Re: Notes on the Go2 Generics Draft
#102Earlier quoted context omitted.
Same here, as a security consultant reading Golang is always a pleasure. I'm pretty sure that the strongest codebases I've seen were in Golang just because of how easy it is for everyone to read the code and actually spend time looking for logic bugs instead of trying to understand what is happening. Developers love to be able to write their magical code and their clever abstractions and often forget that their code…
> Developers love to be able to write their magical code and their clever abstractions and often forget that their code is paying the price by becoming less clear and less readable. Clearly, that justifies the fact that you can't sort an array of doubles and an array of floats with the same function.
Re: Notes on the Go2 Generics Draft
#103I’m a fellow generics pessimist. Having come to Go from Java some 6 years ago I initially found the lack of generics a curious, sometimes frustrating omission. After years of using Go daily and reading a long succession of posts on the go-nuts mailing list wherein Rob Pike, et al, repeatedly and staunchly defended the lack of generics as necessary – even beneficial – in the pursuit of designing a small, readable, coh…
Speaking of Rob Pike, don't see his name on any of the Go2 proposals. His lucidity and circumspection are sorely missed. Could we be witnessing the psychological phenomenon of a "second-system effect" -- as described in The Mythical Man-Month -- writ very large?
The impression I get is that Russ Cox is pretty much the Chief Designer right now (pardon the Sergey Korolyov reference). The original three authors have said that they would not add a feature to the language if one of them opposed it, which is how they kept it simple. I wonder if rsc has anyone to say "no" to him.
Re: Notes on the Go2 Generics Draft
#104Earlier quoted context omitted.
Writing the exact same code for float and double (and possibly complex float and/or complex double) sucks. You've created some straw man about dopamine junky programmers because you don't need generics for whatever it is you do. If you wrote numerical algorithms you'd be annoyed at any language which lacks generics.
Ironically generics don't necessarily solve this. C# requires multiple implementations of numeric methods because int/float/etc don't sit in a type hierarchy. It also doesn't really work in Java either because you have to use the Object types. Even in rust this looks pretty complicated: https://travisf.net/rust-generic-numbers Maybe it's easy in c++? I've seem a similar comment made on almost every discussion of this…
Re: Notes on the Go2 Generics Draft
#105It looks complex.
Re: Notes on the Go2 Generics Draft
#106It's impossible to defend the lack of generics in golang in the face of the fact that two of the larger open source projects both invented their own generics implementations. https://medium.com/@arschles/go-experience-report-generics-i... https://github.com/google/gvisor/blob/master/tools/go_generi...
A bit of history: this tool was originally created specifically for two packages, a linked list package, and a tree-based data-structure package. Both of these used an interface for the entry types, but this had two main drawbacks:
1. Interface assertions and conversions are (often) not free. These packages are used heavily in our critical system call handling path and this was costing on the order of a couple hundred nanoseconds in the critical path (total cost of the critical path is ~1500-4000ns depending on the syscall).
2. Escape analysis does not work across interface methods, requiring heap allocation of pointer arguments. This was less of an immediate problem for the initial creation of go_generics, but annoying to work around in the critical code where it mattered.
The go_generics tool solves both of these problems by generating versions of these data structures with concrete types. However, neither of these problems require generics to solve. General compiler and toolchain improvements could solve both. In fact, I imagine that (1) is greatly improved already (we were solving this problem in the Go 1.5 timeframe).
To this day, our code base has a grand total of 5 generic templates:
segment [1], ilist [2]: These are the two packages referenced above.
seqatomic [3]: Synchronization primitive for sequence count protected values. Not safe to use interfaces.
bits [4]: This is the typical "multiple integer types" problems. IMO, this use is overkill, there are only ~20 lines of code to copy.
pagetables Walker [5]: Used in critical //go:nosplit //go:noescape context, where most runtime calls are unsafe.
Given our experience with, and very narrow use of our go_generics tool, I'd actually rather Go not add generics and continue to use specialized code generation in the places we really need it.
I do recognize that there are a lot of other cases where people legitimately want generics and I am not fundamentally opposed to the draft proposal, but this was my long-winded way of saying that our go_generics are not an obvious argument in favor.
[1] https://github.com/google/gvisor/blob/f3060cb1a4ed61199688b5...
[2] https://github.com/google/gvisor/blob/8fee8f4dd5f7257a7eb77c...
[3] https://github.com/google/gvisor/blob/d1bbaf8b2caba906484d5e...
[4] https://github.com/google/gvisor/blob/d1bbaf8b2caba906484d5e...
[5] https://github.com/google/gvisor/blob/d1bbaf8b2caba906484d5e...
Re: Notes on the Go2 Generics Draft
#107It's impossible to defend the lack of generics in golang in the face of the fact that two of the larger open source projects both invented their own generics implementations. https://medium.com/@arschles/go-experience-report-generics-i... https://github.com/google/gvisor/blob/master/tools/go_generi...
As someone that works on gVisor, I disagree with this w.r.t. our project. i.e., the existence of our go_generics tool is not an obvious indication that we need generics in the language. A bit of history: this tool was originally created specifically for two packages, a linked list package, and a tree-based data-structure package. Both of these used an interface for the entry types, but this had two main drawbacks: 1.…
Re: Notes on the Go2 Generics Draft
#108Earlier quoted context omitted.
That means Go is not the right tool for you. Don't use it. It's so sad to see people pushing to radically alter a language that they will probably never use because it will never be suitable for their needs.
No, Go is not currently the right tool for me, but it's close, and it would be much closer with (usable) generics. What's "so sad" is you think this Reddit style "Don't use it" imperative is an acceptable way to talk to people. You're rightfully afraid of complexity creeping into an otherwise clean language, but it would suck less if you said it better.
I won't argue with you my use of the imperative mood as I'm not a native speaker. I'll take note of it.
Re: Notes on the Go2 Generics Draft
#109The proposal reads like an attempt to add generics to a language that was not conceived to include it in the first place. It looks complex.
Re: Notes on the Go2 Generics Draft
#110Earlier quoted context omitted.
Maybe that's the issue. From what I have seen, the lack of generics mainly becomes painful when working in the numerical space. If I work on mapping JSON, doing APIs and CLIs I don't really need generics. If I work on algorithms and data bags then it starts to be annoying re-implementing the same thing over and over again. So in these discussion you have devops-type people mainly dealing with APIs that are perfectly…
> mapping JSON I find that an ideal set of tools allow us to describe our task and write our code using the same idioms. The fact that "mapping JSON" doesn't actually involve calling "map" on JSON data is a great example of why not having generics in golang is frustrating for me.
Mapping functionally it worth it if the transformation between A and B is regular enough. But things are dirty. Some irregularities appear and now the perfect higher-order function doesn't work nicely anymore. With the imperative approach it just means adding 1 -3 more lines.