5 ms·
Go has had generic List<> and Map<> since before Go 1.0, though. It's really interesting you used those as your examples because that need was fully met in a t
by mappu 5y ago
Go has had generic List<> and Map<> since before Go 1.0, though.
It's really interesting you used those as your examples because that need was fully met in a type-safe way already, and other examples are actually much rarer to come by.
- erik_seaberg 5y agoThe behavior of builtin maps can’t be customized at all. Now at least it’s possible to define a sorted or threadsafe or immutable map with a typesafe API, though it takes replacing all reads and writes with method calls.
- xyzzy_plugh 5y agoNot being able to customize built-in containers is a huge win in terms of readability though. Principle of least surprise and all. If I see a map or slice I know exactly how it behaves, how much memory it consumes, what the runtime behavior is. If you make those generics instead then I have literally no fucking clue what's going on.
- brabel 5y agoIt's even more interesting you chose to actually comment on the particular example I gave rather than general generics for user-defined types, which is clearly what I was talking about. Trying to counter argue against an example by using the actual example, rather than the point the example is trying to convey, is a common, but quite dishonest debate strategy.