2 ms·
I guess the point I wanted to make was that having proper generics in a language is very hard and whats why very few languages attempt to implement it. And peop
by pawadu 10y ago
I guess the point I wanted to make was that having proper generics in a language is very hard and whats why very few languages attempt to implement it. And people are still arguing whether generics in C++ do more harm than good (i.e. complicate debugging).
So not supporting generics is a design decision and not always a bad one.
- coldtea 10y ago>I guess the point I wanted to make was that having proper generics in a language is very hard and whats why very few languages attempt to implement it. I'm not sure about this, I believe it's a solved problem. Languages have had them for decades, and lots of different avenues have been explored. Neither Java nor C# (and those are mainstream pragmatic languages, not experimental academic affairs) have particular issues with their (different) respective Generics implementations (except the obvious tradeoffs I mean -- but it's not like programmers or their compiler writers are strugging because of them in any way). They are also quite easy to add to a language (even hobbyist languages have them) -- I'm not sure why you say that "very few languages attempt to implement it". The big two used by tens of millions (Java and C#) have them, C++ has them, F# has them, Swift has them, Scala has them, Delphi had them, lesser used languages like Ada, Julia, Haskell, D etc have them. Heck, almost all modern mainstream languages have them. "Proper generics" is a red herring put forth by Pike, where its would only be OK to have generics if it came without any tradeoff at all, where tradeoffs even include the compiler being harder to write. Yeah, I don't think they can magically created pain free either. I do think they solve a lot of pain where it matters: for the programmers. >And people are still arguing whether generics in C++ do more harm than good (i.e. complicate debugging). That's because generics in C++ come with all the template baggage and a full turing-complete and complicated scheme to work with them. There's no need to go there.
- codygman 10y ago> "Proper generics" is a red herring put forth by Pike, where its would only be OK to have generics if it came without any tradeoff at all, where tradeoffs even include the compiler being harder to write. This. To further add to this, an argument against generics used to be worries about showing compile times, but that didn't stop rewriting the compiler in Go or implementing SSA. Go's compile times are still much slower than they were. Point being that generics aren't seen as important, not as being too difficult to implement correctly.
- remus 10y ago> ... but that didn't stop rewriting the compiler in Go or implementing SSA. Go's compile times are still much slower than they were. I think the trade offs in those cases were pretty clear. The switch from c to go was made so that compiler development would be easier, and indeed you could well argue that it was a big enabler in work like reducing GC pause times. Similarly, one of the big reasons for switching to the SSA back end was to enable improved optimisations down the line. I think the results of this work are fairly clear already: in 1.7 binaries are generally smaller than 1.6, sometimes by as much as 20-30%. I think the trade-offs for generics are less clear. Compile times may increase, they'd add complexity to any implementation and, perhaps most importantly, they'd add significant complexity to the language. On the other hand, they make certain classes of problem substantially easier and significantly simplify some APIs.
- remus 10y ago> I'm not sure about this, I believe it's a solved problem. No doubt it's possible, the question is can you do it without adding lots of language complexity and corner cases?