4 ms·
Which interfaces-based solution? The one used by sort is a hack that only works for some of the things that you would want to do. The one where you use intros
by btilly 7y ago
Which interfaces-based solution?
The one used by sort is a hack that only works for some of the things that you would want to do.
The one where you use introspection performs badly and isn't typesafe.
The tree implementation in the article cannot be done in a safe and performant way in Go today.
- haolez 7y agoThe one mentioned in the article. It's not a hack: it's a runtime equivalent that requires that your type implements some interface.
- btilly 7y agoIt is a hack. The article lists a whole series of things that are standard in other languages that you can't do in go. Here are some examples: Find smallest/largest element in slice Find average/standard deviation of slice Compute union/intersection of maps Find shortest path in node/edge graph Apply transformation function to slice/map, returning new slice/map And here are data structures that other languages have but go does not: Sets Self-balancing trees, with efficient insertion and traversal in sorted order Multimaps, with multiple instances of a key Concurrent hash maps, supporting parallel insertions and lookups with no single lock If it were not a hack, then go would not have these limitations.
- majewsky 7y ago> Multimaps, with multiple instances of a key Isn't this just map[Key][]Value? The standard library uses these in several places, e.g. url.Values and http.Header, with assorted utility functions.
- btilly 7y agoYou should send that feedback to the author of the article. I literally just cut and pasted those lists.