3 ms·
I don't really think it's fair to argue arrays as an example of generics since they've been around since the dawn imperative programming languages and have been
by laumars 12y ago
I don't really think it's fair to argue arrays as an example of generics since they've been around since the dawn imperative programming languages and have been a staple in the kinds of languages that people example as having a lack of generics.
I'd also question whether maps are a good example either since a map[string]interface{} would be incompatible with a map[int]interface{} (which leads to many of the code duplication examples that developers demonstrate when discussing the need for generics in Go)
Maybe I'm splitting hairs, but this would likely be the mindset that Pike et al have with regards to "generic" built in types.
I do agree with you that there is "some level" of generics on Go though: interfaces{}. Sadly that feature was "uglified" by the constant need for casting (and that's putting it politely).
- jerf 12y ago"I'd also question whether maps are a good example either since a map[string]interface{} would be incompatible with a map[int]interface{}" The map is what is generic, not a specific map. List<Int> is not "compatible" with a List<Char> in any implementation of generics; how could it be? What would that even mean? There isn't a good way of taking a "map", just any "map", but that's a separate problem. Not all languages that have generics can do that, either, only some of them. (A recurring issue in these discussions about Go is that people end up bringing the union of all possible things that generics have ever done, anywhere, to the party, but in reality no language actually has all of those features at once. Real generic implementations, when not being discussed in the context of Go, are usually being discussed in how they are broken. This is what ultimately brought me peace in this argument... in the abstract, it's totally obvious that Go ought to have generics. In the concrete it's a great deal less obvious, and real implementations all do indeed have their serious problems once you get down to the nitty-gritty of what assembly instructions they would actually execute, and exactly how the compiler would produce them. It's all fun and games when you're just waving hands around.) interface{} isn't a "generic" in any sense.
- laumars 12y ago> The map is what is generic, not a specific map. List<Int> is not "compatible" with a List<Char> in any implementation of generics; how could it be? What would that even mean? Well, arguably there are languages where that's possible. PHP does some odd things with maps and arrays, and Perl hashes don't have any distinctions between strings, integers nor floats (or at least none that I've run into - please correct me if I'm wrong). Though I will grant you that I'm now comparing strongly typed languages to weakly typed ones. I think my problem here is although I cut my teeth on statically typed languages, my exposure to generics in those languages was rather limited (in fact does Pascal even support generics?). So I'm possibly misunderstanding the usage of generics in modern strongly typed languages.