4 ms·
>Popular language missing essential feature But is it an essential feature? I've written a lot of Go code and I'm perfectly fine without generics. It makes my
by emersion 8y ago
>Popular language missing essential feature
But is it an essential feature? I've written a lot of Go code and I'm perfectly fine without generics. It makes my code a lot simpler, no need to abstract everything into Thing<OtherThing implementing Stuff, YetOtherThing<Thingie implementing This or That>>. By the way, C doesn't have generics.
If you really need generics that badly for your use-case, nothing stops you from using another language.
- alexandercrohde 8y agoI'm not super educated on this, but the example I'm asking is "How would you port the library lodash to your language without generics?"
- weberc2 8y ago"Porting lodash" isn't an end unto itself, but you can use `interface{}` everywhere and have the same degree of type safety that lodash enjoys, which is to say zero.
- norswap 8y agoIf you nitpick enough, nothing is essential. We can write everything in C, or heck, even assembly. "If you're not happy go look elsewhere" doesn't move the needle on the question "Should Go have generic" at all. It's not an argument at all.
- emersion 8y agoThen should all languages have all features? As the author explains in the article, I don't think all languages should try to solve all problems perfectly.
- norswap 8y agoI don't see how that is the point I made. The point I made was that an argument should be given as to whether a feature should be in the language or not. Note that this leaves the possibility that a feature should not be in the language, even if it does solve a real problem. Both arguments do not address whether the language should have a feature or not. "Not essential" might be recast as a valid argument, but must be rephrased in terms of cost vs benefits of the feature examined wrt the goals of the language.
- bunderbunder 8y agoBringing up C invokes my suspicions about this debate: It's really people with totally different use cases talking past each other. C doesn't have generics. Java has extremely limited generics. In both cases, it means that it's annoying and difficult for me to write a decent math library. I have to choose among making it support only one numeric type, implementing many copies by hand (one for each numeric type), or using some sort of ugly code generation tool - who knows what in Java, the preprocessor in C - to implement all those copies. Which might not be a problem for everyone, but, for my use case, it's annoying. (Deliberately avoiding the "generic library of data structures" use case because, while generics are what brought that to most of us (edit - in the world of static typing), it would appear that Go's handling that case just fine without them.)
- pjmlp 8y agoC does have generics since C11, although relatively constrained.
- bunderbunder 8y agoTo me, despite the name, _Generic(...) doesn't really count. It's more like a switch statement that lets you switch on a type instead of a value. You still have to manually write all your own implementations, which leaves you firmly in territory covered by the 2nd option I listed. Maybe I'm missing something, though. On the rare occasion that I write C code, I stick to C99, so I haven't had much occasion to use it.
- emersion 8y agoI'd say either resort to code generation or pick another language that fits better your use-case.
- bunderbunder 8y agoYeah, sorry if I wasn't being clear. That's pretty much the line I was thinking along. It's perfectly fine for Go's answer to be, "Go doesn't have generics because generics aren't needed to solve the kinds of problems Go is designed for solving, and we are not trying to be a kitchen sink language here. If generics are something you need, please pick a language that's designed to solve the problems that you're trying to solve." But that's a far cry from what TFA said. TFA read more to me as, "Go doesn't have generics because generic programming is a half-baked idea that isn't ready for prime time."
- pjmlp 8y agoOf course it isn't an essencial feature, all the older timers here had to code with programming languages without generics support for a couple of decades. By the way, C has minimal generics support since C11.