3 ms·
For those who are against generics (in general, or with Go specifically), what's your particular rationale? I find myself unable to create an effective anti-gen
by Jtsummers 6y ago
For those who are against generics (in general, or with Go specifically), what's your particular rationale? I find myself unable to create an effective anti-generics argument in the same way I can make a pro-generics argument.
So far what I've seen here seem to be:
- You can already use interface{} for something similar to generics
- I don't want the language to become more complex
- I can't conceive of how it'll be done efficiently/effectively
- I don't, personally, see the value of generics (i.e., it wouldn't change any code I've ever written)
- gher-shyu3i 6y agoIt seems that most people who don't want generics are not able to provide good arguments in support of them. Just hand wavy ones like "I never needed them" or "complexity", even though complexity is inherent in reality. I've seen tons of golang code that would have been much simpler, and less error prone if the language had generics.
- loopz 6y agoSome people just don't want genetics. Maybe never seen the use. Some just want to avoid C++ templates and all those warts. I think the consensus is that Go community want it done right, or not at all.
- gher-shyu3i 6y agoDone right how? Practically every way that generics can be done is already done (C++, Java, C#, and Zig cover practically all bases). It seems very hand wavy for some people to say they want it done right, as if there's a magical way that hasn't been invented yet that will find its way into golang, which is known for being a language from the 70s as far as features go.
- loopz 6y agoIn a way promoting non-convoluted code. It's a property of the language which is like a side effect. Kind of reminds me of Ruby except Ruby was too dynamic to achieve it. C# is very readable too.
- lhorie 6y agoMy understanding of the trade-offs have to do with primarily with devil-in-the-details stuff, i.e. how the feature actually gets implemented. AFAIK, there are two major philosophies: implement boxed types (which Go kinda already has, via `interface {}` being implemented as tuple of (type, value), or very aggressive static analysis (like Rust). The problem with the former is what you get in Java: can't make generics of primitives, and runtime perf issues with boxing/unboxing when you want to e.g. sort terabytes worth of ints. Conversely, the problem w/ the Rust approach is that the cost is shifted over to the compiler, which has to figure out how to emit optimal primitive-handling code given that the entry point of a generic call tree might be very far away (or even unknown at compile time). This leads to slow compilation times. For go specifically, I think there's some amount of worry wrt overlapping features (given how go does interfaces) and the subsequent loss of clarity, given that go falls closer to the one-way-of-doing-things side of the scale. All of these concerns are of the death-by-thousand-paper-cuts variety: can I live with a bit slower compilation times? Yes. Until it's so slow that I can't. Will I love generic collections? Yes. Until I'm neck-deep in a J2EE-like over-architected mess. Etc. Recall that go comes from Google, where minimizing the amount of crap in a billion LOC codebase is considered very important, so concerns like trading off simplicity and compiler speed for other benefits tend to be thought in terms of how the negatives look in the absolute worst case scenario.
- Jtsummers 6y agoMy Go is very rusty so I was spending some time refreshing my memory on the empty interface. As I understand it, in the worst case that Go's generics are implemented with boxed types and a pretty wrapper around the empty interface, you end up with equivalent performance to today but with clearer code (within functions, function declarations becoming somewhat more complicated but not excessively so). But in the best case, this information being given to the compiler will give you clearer code (same qualifications as previous paragraph) and better performance as run-time type verification is moved to compile-time. I suppose if you never use the existing workaround (empty interfaces), then there's no benefit to you in having generics available. But if you do, it seems to me that you're going to get some benefit.
- 6y ago
- confidantlake 6y ago> I don't want the language to become more complex Is the biggest reason for me. If I were the only one using a language I wouldn't care. But working on a team and having to deal with other people's towers of abstraction is awful. Without generics I wouldn't have to deal with it.