5 ms·
What is the Go way to implement a generic data structure that can't be trivially realised by wrapping a couple maps and arrays into a struct (without using inte
by mrkgnao 9y ago
What is the Go way to implement a generic data structure that can't be trivially realised by wrapping a couple maps and arrays into a struct (without using interface{} and throwing away the safety Go's type system, such as it is, provides)?
- verroq 9y agoYou first reconsider your need to make a generic data structure and evaluate on a case by case basis.
- mrkgnao 9y agoMhm, sure, I can go back a couple decades for the sake of argument. Say I can make do with instances of my data structure for, I don't know, int8, int16, and strings.
- matthewmacleod 9y agoThat's a glib answer. You end up with a bunch of duplicated code when you do this.
- verroq 9y agoHow often do you implement generic data structures in your code? The last time you wrote one was probably in your data structures class.
- mrkgnao 9y agoThere are many, many, many "legitimate" "real-world" situations where you need data structures ouside of the two or three Go gives you by default. Queues? Dequeues? Trees, for the love of $DEITY? Tries? Sets? Effective use of Golang is really teaching yourself to think that anything beyond the language is a useless distraction or some kind of academic pretension. I won't go so far as to call it S________ S_______, but this is textbook Blub.
- pcwalton 9y agoThe last time I wrote one was a few weeks ago. I've written dozens of them during my career.
- concede_pluto 9y agoI needed a ListMultimap a couple of weeks ago. Fortunately it had already been implemented for me because my language doesn't prevent that.