5 ms·
Bringing 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. Ja
by bunderbunder 8y ago
Bringing 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."
- bunderbunder 8y agoOr, to throw a third option one out there -- "Go doesn't have generics because they would interact poorly with some other aspect of the language." That works, too. For example, it's why F# continues not to have ad-hoc polymorphism, despite many users clamoring for it. I'm inclined to agree with the project's maintainers on the subject. As useful a thing as it is, and as glaring as it is for a modern descendant of ML not to have it, it's hard to see how it could be added without creating all sorts of language warts.
- louthy 8y agoBoth F# and C# can do ad-hoc polymorphism - I use it in my language-ext library [1], the library is C# but the principle is the same for F#. It's not idiomatic (or pretty), but it's possible if needed. Higher-kinds is the killer missing feature. [1] https://github.com/louthy/language-ext#ad-hoc-polymorphism https://github.com/louthy/language-ext#ad-hoc-polymorphism
- llimllib 8y ago> I think Go should be comfortable not being suitable for writing certain classes of programs. I don’t think programming languages should compete with each other in an attempt to become the perfect solution to every problem. This is impossible, and attempts will just create a messy kitchen sink that solves every problem poorly. is a quote from the article, and seems to say exactly what you're saying?