Live data from Hacker News

Generics enabled by default in Go tip

go-review.googlesource.com

191–200 of 378 posts

Re: Generics enabled by default in Go tip

#191

Earlier quoted context omitted.

They also have absolutely terrible performance due to poor cache locality and putting pressure on GC

They make a great stack, though. Cheap to use and easy to implement.

Use a deque at least and amortize the heap allocations...

Re: Generics enabled by default in Go tip

#192
post #42

Earlier quoted context omitted.

a couple high profile projects (k8s) needed generics, there are limited use cases outlined in the planning docs that detail the holes in the language they're filling, it wasn't just squeaky wheels.

Shame how k8s was a failure without generics. Think what could have been.

The thing is, Google is paying most of the development costs for Go and Google controls Go too. It makes sense to adapt the language to their needs. They already do stuff like creating new network protocols because it will reduce their costs.

Re: Generics enabled by default in Go tip

#193
post #48

Earlier quoted context omitted.

Without generics, I have seen terrible and unreadable golang code. There is no tool that can not be mis-used. Generics are adding a tool to the toolbox. They can be used well or they can be mis-used. I recently wrote a gui app in Golang using Fyne and I really wish I'd had generics for some of the UI handling - instead I ended up having to write some really ugly and not simple code to handle the case. The end result…

Can you give an example of terrible unreadable go code due to a lack of generics? I’ve grown to love go because it’s one of the few languages where I can jump into a new code base and relatively easily understand what is going on.

> Can you give an example of terrible unreadable go code due to a lack of generic

https://news.ycombinator.com/item?id=28254411

The "solution" to this is copy-pasted boilerplate code with casting for every call.

Re: Generics enabled by default in Go tip

#194

Earlier quoted context omitted.

Either a language changes to keep interest up and bring in a new audience, or it's left behind by advances to and the status quo (and what's considered a minimum set of features) and stagnates. Just look at Perl. Stuff written 20 years ago is likely to work without change on the newest release more often than not. For certain work contexts, like system utilities and long life core programs, this can be amazingly usef…

C

To add to what other people said, the tooling around C has changed a lot since C was created, partially because there's already so much code in C. The Linux kernel is 20/30 millions lines of code of C mostly, Kubernetes is below 2 millions. So at this point you can still change the language a bit. With C it's harder, so instead people invest in tooling (and replacements).

Re: Generics enabled by default in Go tip

#195
post #21

Earlier quoted context omitted.

How would you write a singly linked list who’s contents are arbitrary? What if you were to map a function over it? Say you want to use this data structure with third-party objects? How do you do that right now?

Find a different way to solve the problem. I've written close to half a million lines of code in Go and the lack of generics has been a pain point in maybe 1% of that? Usually, if you are thinking about generics you are reaching for abstraction when you don't need to be. If you really need generic structures you can use the interface type but generally there's a simpler solution that doesn't require generics.

I also wrote hundreds of stuff from 1986 up to 1994, my first experience with generics, on Turbo C++ for Windows 3.1.

Doesn't mean many of us want to keep living on that world.

I advise reading books like "From Mathematics to Generic Programming"

Re: Generics enabled by default in Go tip

#197
post #23

Earlier quoted context omitted.

How would you write a singly linked list who’s contents are arbitrary? What if you were to map a function over it? Say you want to use this data structure with third-party objects? How do you do that right now?

You wouldn't. Everybody goes into Go thinking that's absurdly confining. Some significant subset of Go programmers learn that they instead find it liberating. Programming is programming; you have an overwhelming number of degrees of freedom no matter what language you work in. It sometimes turns out that taking some of those degrees out of the language makes it easier to focus them on your problem domain.

It's not like this is some kind of new or unfamiliar experience. Many programmers had to deal with something like that in Java or C#, back when they didn't have generics. There's a reason why both got them eventually.

Re: Generics enabled by default in Go tip

#198
post #98
post #96

Earlier quoted context omitted.

There are certain things that just can’t be done without generics, though. Type safe higher order functions, type safe custom collections, etc. Of course, perhaps these are all just subjective to you, because you can still write any program you need without them. But not having this feature does constrain the set of type-safe programs you can write quite a bit.

I feel like it pretty much always turns out that the things you can't do without generics are, like, second-order things. Higher order functions, type safe custom collections, those are tools. What we care about mostly is what we actually build , and people build pretty much everything in every language, generics or not.

By the same token, functions in general are second-order things - you can build things just fine with GOTO, and plenty of real-world software was built like that back in the day. But we don't do that anymore.

Re: Generics enabled by default in Go tip

#199
post #64

Earlier quoted context omitted.

They are complex. I’m guessing you haven’t thought about them much beyond the trivial use cases.

No, it's relative. For the top 5% - 10% of developers, generics are a useful tool for doing their job efficiently. For the bottom 50% of developers, generics are complex and confusing, and only provides more footguns.

For 0.5%-1% C++ is a powerful tool which allows to quickly (thanks to rich abstractions) to write high-performance code.

For merge mortals it is a tool hard not to misuse full of hidden traps and debugging of code written even by the very best developers (surprise - it has bugs too) is a challenge.

Go just did a step towards C++, even if a tiny one.

Re: Generics enabled by default in Go tip

#200
post #88
post #78

Earlier quoted context omitted.

Or use Option or Result, so your error handling is small and forcibly correct.

Error handling in Rust isn't always small or straightforward. I miss both options and match expressions when I switch back to Go from Rust, but there's also tangles of or_else's and maps and the fact that everyone uses third-party libraries to work out the types for errors. There's tradeoffs everywhere you look.

Zig is probably a better comparison for this:

https://ziglang.org/documentation/master/#Errors

Post reply on HN