Live data from Hacker News

How generics are implemented in Go 1.18

github.com

191–200 of 228 posts

Re: How generics are implemented in Go 1.18

#191
post #187

Earlier quoted context omitted.

You clearly have no idea what Rust is for, or who the target audience is. Application developers do not need a non-GCed language, and anyone who argues for the added complexity and noise (because Rust makes it so easy you'll say) is actually just looking for something cool to learn and push at the office. I get it, you don't want to write Go, it's too simple for the 1%er programmers. I've been a kernel developer for…

You clearly don't have any idea who I am, or my opinions on Rust. Since I feel like educating you, > Nothing really, Rust's killer application are domains where using a language with automatic memory management and support for value types isn't an option, trying to use it elsewhere, while possible is sacrificing productivity. https://news.ycombinator.com/item?id=30391431 That doesn't change the fact that many relevan…

>You clearly don't have any idea who I am

Why would anyone here have any idea who you are? Your username is not informative, and you don't say who you are in your profile. That's perfectly fine, of course, but you can't then expect people to recognize you as being a particular individual.

Re: How generics are implemented in Go 1.18

#192

Earlier quoted context omitted.

I’m not going to defend what random internet commenters may have said, but in my view the core team has been fairly consistent and their design decisions (to me) make sense. The first thing to understand is that Go occupies a space lower level than Java but higher level than C. It includes things like explicit pointers and more control of memory layout. Many of the design decisions make no sense without that context.…

> On generics, I think the team’s position has mostly been that it’s a big project and there’s been other priorities like rewriting the compiler in Go, improving the GC, etc. And that in the spectrum of trade-offs for generics systems they didn’t want to go all the way to Java or C++. That was not the initial team position. Their initial position was "why would you even need generics? Please provide us a usecase". Th…

>Their initial position was "why would you even need generics? Please provide us a usecase"

Do you have a source for this? It doesn't match my recollection. As I recall, the Go team always said that they may add generics in the future, but also that they would also like to see compelling use cases for it. That is not an unreasonable request.

Re: How generics are implemented in Go 1.18

#193
post #187

Earlier quoted context omitted.

You clearly have no idea what Rust is for, or who the target audience is. Application developers do not need a non-GCed language, and anyone who argues for the added complexity and noise (because Rust makes it so easy you'll say) is actually just looking for something cool to learn and push at the office. I get it, you don't want to write Go, it's too simple for the 1%er programmers. I've been a kernel developer for…

You clearly don't have any idea who I am, or my opinions on Rust. Since I feel like educating you, > Nothing really, Rust's killer application are domains where using a language with automatic memory management and support for value types isn't an option, trying to use it elsewhere, while possible is sacrificing productivity. https://news.ycombinator.com/item?id=30391431 That doesn't change the fact that many relevan…

I'm not worried about Go in the slightest, and based on your other comment it sounds like we share somewhat of the same opinion on overuse of Rust so I will apologize for jumping the gun. But most of these userland uses of Rust are stupid and the parts people believe they need Rust for will be eaten up by eBPF anyway. Kernel development you still need a stable ABI, and while I already said I think Rust makes sense for drivers/FS (using bypass or as a module) or system internals it's not yet a good language for a full operating system unless you're willing to write the entire distribution in Rust. People still have a bad taste in their mouth for GC and I get it. But these aren't the early years of Java. Google has some of the best mm minds money can buy and most people aren't going to outplay them at their own game. I would also argue that using Go for systems programming is also stupid. Setting up freestanding Go is a PITA and again, no stable ABI, nothing in the language that makes it particularly better than long standing systems languages or a language that is actually innovating in the area (Rust). People say pick the right tool for the job but that's just salesman talk for use the tool that seems the coolest that management will let us use.

Re: How generics are implemented in Go 1.18

#194
post #94
post #49

Earlier quoted context omitted.

Note that if a plugin and the main program have any packages in common, the build-hash (Go binaries include a hash for each included package) must be identical between the program and the plugin. If the hashes don't match, then the program's `plugin.Open(…)` call will return an error. So if there is a package in common such that an implementation change could cause something like a cgshape change, well the cgshape ch…

Does this even include the standard library?

Yes, it does include the standard library.

Re: How generics are implemented in Go 1.18

#195

Earlier quoted context omitted.

> a slice of structs that implement an interface should be able to be used as a slice of that interface It absolutely should not even if it could (which it can not since the memory layouts don’t match), as that undermines the type system.

If it were immutable at least, the type system wouldn't be undermined at all.

> If it were immutable at least

Yeah but immutability’s not even remotely a thing in go land.

Re: How generics are implemented in Go 1.18

#196

Earlier quoted context omitted.

> Every few years someone gets me to try Go out again and I discover, yet again, that it's still struggling with problems that were solved before it existed. It's a shame that this language has stolen so much mind share from more deserving languages. Go steals the mindshare because it focuses on the important problems that other languages neglect in part or in full: performance, tooling, ecosystem, simplicity, readab…

Sorry, but I just don't buy it. Performance just isn't the problem people say it is. I've done a lot of Python development over the last 12 years, and in that time, I've run into lots of performance problems, but none that would have been easier to solve in Go and none that were particularly hard to solve in Python. In most cases you're just offloading onto libraries (i.e. Pandas or MPT). I've dipped into C a handful…

> Performance just isn't the problem people say it is. I've done a lot of Python development over the last 12 years, and in that time, I've run into lots of performance problems, but none that would have been easier to solve in Go and none that were particularly hard to solve in Python. In most cases you're just offloading onto libraries (i.e. Pandas or MPT). I've dipped into C a handful of times, but that was more of a "could" than a "had to".

I strongly disagree. I've been doing professional Python development for the last ~15 years, and there are some cases where you can call out to C/Pandas or multiprocessing or something, but overwhelmingly you end up spending more time marshaling to C data structures or pickling than you save. Specifically, I've had to port services to use a Spark cluster to offload the processing because even Pandas was inadequate (80th percentile requests would take more than 60s for a CPU intensive task, and they were also blocking the async event loop). This just isn't a problem in Go because (1) single threaded execution is often 100x faster than in Python and (2) parallelization is trivial and (3) you can easily optimize Go by moving allocations out of a tight-loop (no such thing in Python).

> But usually that sort of stuff is automated out in the first week of development anyway--is that really enough to justify choosing a language?

No, I don't think this is a make-it-or-break-it feature, but it's nice. Moreover, there's a lot to good tooling besides static binaries--reproducible dependency management, no need to set up CI to build/publish packages and docs, build systems that don't require scripting or extensive configuration (any Go developer can jump into almost any Go project), dead simple cross-compilation, standard formatters, etc.

> Ecosystem? I'm not impressed. There are like 10 languages with healthier, more active ecosystems.

The way that I think about it is that you're either in the top 5 languages or you're not; it doesn't matter much where you rank in that tier because once you're in that tier you're pretty much guaranteed to get first-class support for APIs. For example, Kubernetes, Docker, AWS, GCP, etc are pretty likely to support API clients in JS, Python, and Go. Java would probably be next and perhaps C# eventually. For the foreseeable future, Rust will probably have to rely on the community to maintain these kinds of packages. The salient point is that Go is in the top tier of languages which get first-class support, not that its ecosystem is head and shoulders above everyone else.

> "Simplicity" is generally a pretty bad argument, because what's simple is so subjective. My observation is that simple problems are simple in Go, which makes it a great language for demos, but if you actually try to solve complex problems with it, the language completely lacks features with sufficient abstraction to make complex problems simpler.

I agree that "simplicity" is subjective, but I disagree that Go is only well-suited for demos. Solving complex problems is pretty simple with Go; however, Go doesn't do well for eliminating boilerplate (local repetition) which is fine because boilerplate isn't where your bugs come from and in most cases trying to DRY up boilerplate leads to code which is much harder to understand (e.g., while a single map()/filter()/fold()/etc is pretty easy to understand, long chains get convoluted fast while a single for loop remains pretty easy to grok (even in Python, we tend to frown on complex list comprehensions in favor of nested for loops). The real value add for Go's kind of simplicity is that anyone can jump into a Go project and write basically the same kind of code that anyone else would write--there isn't much room for personal flourishes, everything is bog standard. Go is bad for "code as art" or flexing your cleverness, but it's great for developing software.

> Readability: this sort of goes back to the simplicity thing. Sure, go has less boilerplate than some languages, but that only matters for the simple stuff.

Per my previous paragraph, Go's readability isn't in reducing boilerplate (Go is famously criticized for failing to reduce boilerplate) but because everyone writes the same code and the code is fairly simple (e.g., no "inheritance vs composition" debates). Further, the ubiquity of gofmt is also pretty amazing. Some languages are catching up with the "standard formatter" idea (Python, Rust, etc), which is great, but nowhere is it as ubiquitous as in Go.

> Learning curve: beating a dead horse here, but just because it's easier to learn to solve simple problems in go, doesn't mean it's easier to learn how to solve professional-level problems with go, let alone industry-leading problems which actually constitute the competitive advantage of a business.

It's much easier to onboard developers to Go than to Java or C++ or even Python. Being able to bring on a new developer without spending days configuring their developer environment, etc is pretty great. Open source projects can attract contributors immediately and businesses don't need to restrict their hiring pool to people with previous Go experience.

> Go steals the mindshare because people saw Google were using it and mistakenly thought that if Google were using it, it must be good, even though almost nobody has the same problems as Google.

This is lazy argumentation, and trivially disproven. If this were the case, people would give up on Go and return to whatever language they came from. Instead, people who use Go for real projects tend to enjoy it or at least have more thoughtful criticisms than "Go is only popular because of Google".

> Just to be clear, I didn't call anyone stupid: on the contrary, I think the developers fell into a trap that is particularly dangerous to smart people: we think that because we're smart, we already know the best way to do things. That's not stupid, it's ignorant. I don't mean that to be insulting although I'm sure you'll take it that way, but I'll say that ignorance is fixable.

I agree, but I think this applies more to Go's critics than to Go proponents. Notably, Go proponents overwhelmingly have experience with other languages, while Go's critics fixate on how Go doesn't let them program in the idioms of their previous language. The people who try Go for more than a few weeks tend to be able to levy more thoughtful criticisms than "Go is stuck in the 1970s"--they can talk about the advantages of standardization even if they still prefer more expressive power, for example.

> It's telling that in your post you just spit out a bunch of buzzwords without any comparison to any other languages

Yes, it tells you that I was commenting from a phone onto an Internet forum and didn't want to make a huge comparison chart in ascii. :) I'm happy to debate the tradeoffs of Go relative to other languages, but it wasn't necessary to make my points.

> which is pretty much how Go got here: Go developers generally only think Go is great because they've never used other decent languages.

This is another lazy criticism. Overwhelmingly Go developers have previous experience in other languages (per the annual Go survey results). In my case in particular, I've used Java, C#, C++, C, and Python professionally and I've dabbled in other languages (e.g., Rust, OCaml, Haskell, etc) on the side. I regularly have thoughtful and articulate debates about the tradeoffs of Go relative to the aforementioned languages, and many of the other Go proponents who post here do as well. Further, I hope you wouldn't criticize Go developers for lacking experience with other languages without yourself having extensive experience with Go.

Re: How generics are implemented in Go 1.18

#197
post #136

Earlier quoted context omitted.

Quoted post unavailable.

Considering it was written by a Turing award winner and other members of Bell Labs and Google, who not only shaped modern day computing but have been doing so for the literal 50 years you referenced, maybe you should consider that the reason that Go is popular and used in many settings is because it's good, and you're the one who is A) suffering from a bad case of Dunning–Kruger B) Have yet to learn the lessons that…

"The key point here is our programmers are Googlers, they’re not researchers. They’re typically, fairly young, fresh out of school, probably learned Java, maybe learned C or C++, probably learned Python. They’re not capable of understanding a brilliant language but we want to use them to build good software. So, the language that we give them has to be easy for them to understand and easy to adopt." – Rob Pike

Re: How generics are implemented in Go 1.18

#198

Earlier quoted context omitted.

I think C# might be the closest mainstream language, but I’d say explicit pointers, interior pointers, and slices as the default list type might be things that make Go programming a little lower level. There are also other differences that would prevent using C#’s system as is - Go doesn’t have the reference/value type dichotomy or inheritance. I think they also wanted to be able to abstract across float/doubles etc…

I'm not sure what the difference is with regards to pointers. They're both garbage collected languages with value types. There are definitely differences in the languages, but I'm not sure that Go really had anything to figure out or invent. I don't buy that argument.

> I'm not sure what the difference is with regards to pointers.

In C# most objects are 'class' objects, which are implicitly passed by pointer, although some are 'struct' objects passed by value. In Go rather than making the decision once at the type level, the decision to pass by value or pointer is made explicitly every time an object is used.

> I'm not sure that Go really had anything to figure out or invent

If you look at the discussions for Go (which started as early as 2009 [1]) [2] [3] [4] [5] generics seems as big or a bigger project as the other improvements made to the language over the last decade. My impression is there being a broad spectrum of potential trade-offs across compile speed, execution speed, convenience, etc.

The totality of the prior art here is above my pay grade, but I can quote the Haskell people they roped in [4]:

> We believe we are the first to formalise computation of instance sets and determination of whether they are finite. The bookkeeping required to formalise monomorphisation of instances and methods is not trivial ... While the method for monomorphisation described here is specialised to Go, we expect it to be of wider interest, since similar issues arise for other languages and compilers such as C++, .Net, MLton, or Rust

I think C# occupies a fairly nice design spot also (and takes advantage of its class/struct system to get fast compiles but also performance when needed). But it's not like the C# design couldn't be improved on. As far as I know you still can't write math code that works across 32 and 64 bit floats. And array covariance is implemented in a way that isn't type-safe and relies on run-time checks and exceptions. [6]

[1] https://research.swtch.com/generic

[2] https://docs.google.com/document/d/1vrAy9gMpMoS3uaVphB32uVXX...

[3] https://go.googlesource.com/proposal/+/master/design/go2draf...

[4] https://arxiv.org/pdf/2005.11710.pdf

[5] https://go.googlesource.com/proposal/+/refs/heads/master/des...

[6] https://codeblog.jonskeet.uk/2013/06/22/array-covariance-not...

Re: How generics are implemented in Go 1.18

#199
post #187

Earlier quoted context omitted.

You clearly have no idea what Rust is for, or who the target audience is. Application developers do not need a non-GCed language, and anyone who argues for the added complexity and noise (because Rust makes it so easy you'll say) is actually just looking for something cool to learn and push at the office. I get it, you don't want to write Go, it's too simple for the 1%er programmers. I've been a kernel developer for…

You clearly don't have any idea who I am, or my opinions on Rust. Since I feel like educating you, > Nothing really, Rust's killer application are domains where using a language with automatic memory management and support for value types isn't an option, trying to use it elsewhere, while possible is sacrificing productivity. https://news.ycombinator.com/item?id=30391431 That doesn't change the fact that many relevan…

Please don't use Discord as an example. They are proprietary and quite hostile to its users through its data and metadata hoarding practices.

Re: How generics are implemented in Go 1.18

#200
post #17

Earlier quoted context omitted.

D, Ada, Eiffel, Delphi go as counter example, and C++ modules are already proving a much better experience in VC++.

Delphi didn't have generics. Not sure about more modern versions, but the power of the generics also impacts compile times. Java generics barely impact compile times at all but they're also nowhere as powerful as Rust and C++ ones.

Delphi added generics in 2009

So it had them roughly as long as Go existed

Post reply on HN