4 ms·
Go, which claims not to have either generics or objects, has both for built-in types. Channels and maps are both opaque objects and parameterized types. The ar
by Animats 12y ago
Go, which claims not to have either generics or objects, has both for built-in types. Channels and maps are both opaque objects and parameterized types. The argument that generics are unnecessary would be more convincing if those built-in types were not needed. The problem is adding generics without making a mess of things. This is harder than it looks.
In the example, there's a set of "int", and a set of "string". A new set is created with
set := set.New()
in both cases. It looks like you could not instantiate "set" for both types in the same program without a name clash. That's no good. Parameterized types for Go make sense, but the types need to be given a user defined name each time you create one. With "generics as a service", you'd have to encode that name into the "import" statement, which is getting a bit clunky.
Go's lack of generics is a reaction to the mess C++ made of them. In C++ the generics system turned into an entire compile time programming environment based on term rewriting rules. Nobody wants to go there again. But Go went too far.
- burntsushi 12y ago> Go, which claims not to have either generics or objects, has both for built-in types. Who is claiming that? > The argument that generics are unnecessary would be more convincing if those built-in types were not needed. This is a straw man that you're tearing down. The Go devs have always acknowledged the utility of generics. They just have a different set of trade offs that they are targeting. More to the point, there's absolutely nothing inconsistent with the position, "If we can make writing code easier with a little blessed generics without sacrificing our project goals, then let's do it!"