News for hackers. Stuff that matters.
Re:Go generics are not bad by maxbond on Friday July 08, 2022 @11:21PM (#32031249)
I'm afraid that it most certainly is, as Rust is the only language I have ever used generics in, and I had this problem.

Lifetimes suffer from the exact same problem as well, since they're really an exotic form of generic.

That said, I will readily admit that it was a lack of skill on my part. From talking to people in the Rust community though, I gather this isn't an uncommon experience.

Re:Go generics are not bad by 4ad on Saturday July 09, 2022 @06:00AM (#32033516)
Lifetimes are viral in Rust because 1. you can't abstract over them, 2. affine types are viral by design, but generics themselves are anything but viral.
Re:Go generics are not bad by hgomersall on Saturday July 09, 2022 @02:07AM (#32032315)
They're not viral in rust - you can always replace the generic with a concrete type in super types.
Re:Go generics are not bad by maxbond on Saturday July 09, 2022 @09:37AM (#32034966)
Well that's rather the point of being generic with any language, isn't it?

You can stop being generic when you have sufficient information to stop being generic. If you're writing a library, that can easily bubble up all the way to the top, because you may never have enough information.

ETA: I think I was using a definition of viral that wasn't entirely correct. I thought it was a casual term rather than a precise one. But it seems like you're saying something is viral if you _must_ pass it on. In which case I apologize, generics are "semiviral" (I'm trying to introduce this term - if it already exists & isn't this, I apologize) - you don't need to pass them on, there's just a tendency to. The result looks very similar.

Re:Go generics are not bad by orthoxerox on Saturday July 09, 2022 @06:06AM (#32033537)
Rust also has associated types, which are exposed to the implementer, but not to the consumer.
Re:Go generics are not bad by maxbond on Saturday July 09, 2022 @09:54AM (#32035099)
I mean, generics and associated types aren't equivalent, but they also are often exposed to the consumer. Eg, if you're accepting an Iterator, you'll want to populate the Item associated type.