3 ms·
The author discounts this as a good solution because you'd have to re-implement the structure and functions for every single type you might put in the map; i.e.
by PeterisP 9y ago
The author discounts this as a good solution because you'd have to re-implement the structure and functions for every single type you might put in the map; i.e. that would be a valid solution iff Go supported generics, but it does not.
- falcolas 9y agoGo's introspection tools do provide enough support to offset the lack of generics, at the cost of having to write your own type checks, and at the cost of having runtime instead of compile time type checking. But it can be done.
- nine_k 9y agoAnything Turing-complete could by definition be run on a Turing machine. But Brainf*k, a straightforward Turing machine implementation, seems less productive than almost any other language.
- krakensden 9y agoPeople say this, but it isn't really true- you could use the sort.Interface interface like everyone else. Consumer wants to use your custom map with their custom type? Make sure it supports Less. Speaking of sort.Interface, people say they want generics, but I think there is an implicit ask for operator overloading, too. Or the code they are asking to not write is probably still going to be there.
- masklinn 9y ago> People say this, but it isn't really true- you could use the sort.Interface interface like everyone else. Consumer wants to use your custom map with their custom type? Make sure it supports Less. 1. So you have a map of sort.Interface, and that's just as absolutely-not-convenient-or-type-safe as a map of interface{} 2. TFA does not want a sorted map, they want an ordered map, so sort.Interface has no relevance whatsoever: the order of iteration of an ordered map is the order of insertion, not the sort order of the elements. > Speaking of sort.Interface, people say they want generics, but I think there is an implicit ask for operator overloading, too. Or the code they are asking to not write is probably still going to be there. Not really. Java does OK without operator overloading. Having to use methods instead of operators can be annoying in some cases (mostly when working with non-built-in numerics e.g. decimals or infinite-precision integrals) but it doesn't limit you much if it does at all.