10 ms·
I kind of gave up on it when I realized how complicated it is to sort a list. Hopefully they'll improve that in future versions. Still could see myself using i
by Tichy 13y ago
I kind of gave up on it when I realized how complicated it is to sort a list. Hopefully they'll improve that in future versions.
Still could see myself using it for specific use cases.
But for the future I'd wish for something cooler to win :-)
Edit: check out the sort module and decide for yourself http://golang.org/pkg/sort/ http://golang.org/pkg/sort/
It has some interesting, if confusing, properties. But why not just let me write
list.sort(function(a,b){ return 1, 0 or -1...}) like JavaScript does?
While the examples in the sort module are perhaps more generic than necessary (hence the interesting but confusing properties), any sort still requires the definition of 3 functions, and they can't be defined inline (on the fly) either, afaik.
- gatestone 13y agoHow is it complicated to sort a list? The only challenge is to provide a corresponding swap function for your list (or for any ordinal "collection" you need), like in this example for arrays, when it is trivial: func (s Organs) Swap(i, j int) { s[i], s[j] = s[j], s[i] } http://golang.org/pkg/sort/#example_Interface http://golang.org/pkg/sort/#example_Interface Also note two things: - This is the efficient and type safe way to handle polymorphism in Go - The standard packages documentation is very nice with live, runnable examples
- Tichy 13y agoBut you also have to implement Len() and Less(), don't you? Maybe you can create a better way, but it is not implemented in the sort package by default. Also I suppose you need to "convert" your list to some other type with the said functions provided (dervied from the standard go lists, forgot the name). Maybe that is a standard go mechanism, but it still amounts to more lines of code. Maybe complicated is the wrong word, longwinded might be better?