{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/16721","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/16721/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/16721/comments","events_url":"https://api.github.com/repos/golang/go/issues/16721/events","html_url":"https://github.com/golang/go/issues/16721","id":171324550,"number":16721,"title":"proposal: sort: add sort.Slice helper for sorting slices","user":{"login":"bradfitz","id":2621,"avatar_url":"https://avatars.githubusercontent.com/u/2621?v=3","gravatar_id":"","url":"https://api.github.com/users/bradfitz","html_url":"https://github.com/bradfitz","followers_url":"https://api.github.com/users/bradfitz/followers","following_url":"https://api.github.com/users/bradfitz/following{/other_user}","gists_url":"https://api.github.com/users/bradfitz/gists{/gist_id}","starred_url":"https://api.github.com/users/bradfitz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bradfitz/subscriptions","organizations_url":"https://api.github.com/users/bradfitz/orgs","repos_url":"https://api.github.com/users/bradfitz/repos","events_url":"https://api.github.com/users/bradfitz/events{/privacy}","received_events_url":"https://api.github.com/users/bradfitz/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/golang/go/labels/Proposal","name":"Proposal","color":"ededed"}],"state":"open","locked":false,"assignee":{"login":"griesemer","id":8528975,"avatar_url":"https://avatars.githubusercontent.com/u/8528975?v=3","gravatar_id":"","url":"https://api.github.com/users/griesemer","html_url":"https://github.com/griesemer","followers_url":"https://api.github.com/users/griesemer/followers","following_url":"https://api.github.com/users/griesemer/following{/other_user}","gists_url":"https://api.github.com/users/griesemer/gists{/gist_id}","starred_url":"https://api.github.com/users/griesemer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/griesemer/subscriptions","organizations_url":"https://api.github.com/users/griesemer/orgs","repos_url":"https://api.github.com/users/griesemer/repos","events_url":"https://api.github.com/users/griesemer/events{/privacy}","received_events_url":"https://api.github.com/users/griesemer/received_events","type":"User","site_admin":false},"assignees":[{"login":"griesemer","id":8528975,"avatar_url":"https://avatars.githubusercontent.com/u/8528975?v=3","gravatar_id":"","url":"https://api.github.com/users/griesemer","html_url":"https://github.com/griesemer","followers_url":"https://api.github.com/users/griesemer/followers","following_url":"https://api.github.com/users/griesemer/following{/other_user}","gists_url":"https://api.github.com/users/griesemer/gists{/gist_id}","starred_url":"https://api.github.com/users/griesemer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/griesemer/subscriptions","organizations_url":"https://api.github.com/users/griesemer/orgs","repos_url":"https://api.github.com/users/griesemer/repos","events_url":"https://api.github.com/users/griesemer/events{/privacy}","received_events_url":"https://api.github.com/users/griesemer/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/30","html_url":"https://github.com/golang/go/milestones/Proposal","labels_url":"https://api.github.com/repos/golang/go/milestones/30/labels","id":1373555,"number":30,"title":"Proposal","description":"Proposals that are pending (not yet accepted/rejected).\r\n","creator":{"login":"rsc","id":104030,"avatar_url":"https://avatars.githubusercontent.com/u/104030?v=3","gravatar_id":"","url":"https://api.github.com/users/rsc","html_url":"https://github.com/rsc","followers_url":"https://api.github.com/users/rsc/followers","following_url":"https://api.github.com/users/rsc/following{/other_user}","gists_url":"https://api.github.com/users/rsc/gists{/gist_id}","starred_url":"https://api.github.com/users/rsc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rsc/subscriptions","organizations_url":"https://api.github.com/users/rsc/orgs","repos_url":"https://api.github.com/users/rsc/repos","events_url":"https://api.github.com/users/rsc/events{/privacy}","received_events_url":"https://api.github.com/users/rsc/received_events","type":"User","site_admin":false},"open_issues":58,"closed_issues":41,"state":"open","created_at":"2015-10-24T01:40:49Z","updated_at":"2016-08-16T04:52:44Z","due_on":null,"closed_at":null},"comments":101,"created_at":"2016-08-16T04:52:44Z","updated_at":"2016-08-19T09:19:35Z","closed_at":null,"body":"I propose we make sorting slices a first class concept in Go 1.8.\r\n\r\nI think everybody appreciates the cute `sort.Interface` type at this point, but the reality is that:\r\n\r\n  * nobody really sorts anything except slices (the handful of exceptions can keep doing what they're doing)\r\n  * the Len and Swap functions are redundant. They're always the same for slices.\r\n  * naming a new type (e.g. \"widgetsByName\") is tedious to many (including me; I still loathe it after 6+ years)\r\n  * making a new type and three methods at the top-level (because it has to have methods, so it can't be a local type) is more difficult to read, since I'd prefer my `Less` function inline with my code, in context.\r\n\r\nI think we should add to package sort at least:\r\n\r\n```go\r\npackage sort\r\n\r\n// Slice sorts the provided slice using the function less.\r\n// The sort is not stable.\r\n// If slice is not a slice, Slice panics.\r\nfunc Slice(slice interface{}, less func(i, j int) bool)\r\n```\r\n\r\nAnd maybe at the same time, or in the future:\r\n\r\n```go\r\n// SliceSorter returns an sorter for the provided slice, suitable\r\n// for with Reverse or Stable.\r\n// If slice is not a slice, SliceSorter panics.\r\nfunc SliceSorter(slice interface{}, less func(i, j int) bool) Interface\r\n```\r\n\r\nThe assumption is that the user's `less` function would close over the data to be sorted.\r\n\r\nFor speed, this would not be purely reflect-based (except for one call to to get the slice length). The implementation would generate a custom swapper as needed for the type of the slice elements such that it's compatible with the GC & write barriers. I did a prototype of this which shows that it's as fast as the typical way.\r\n\r\nI think there's plenty of evidence in the Github BigQuery dataset that we're making sort way too hard for users.\r\n\r\n/cc @griesemer @robpike @ianlancetaylor @adg @broady"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/240970016","html_url":"https://github.com/golang/go/issues/16721#issuecomment-240970016","issue_url":"https://api.github.com/repos/golang/go/issues/16721","id":240970016,"user":{"login":"myitcv","id":3374574,"avatar_url":"https://avatars.githubusercontent.com/u/3374574?v=3","gravatar_id":"","url":"https://api.github.com/users/myitcv","html_url":"https://github.com/myitcv","followers_url":"https://api.github.com/users/myitcv/followers","following_url":"https://api.github.com/users/myitcv/following{/other_user}","gists_url":"https://api.github.com/users/myitcv/gists{/gist_id}","starred_url":"https://api.github.com/users/myitcv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/myitcv/subscriptions","organizations_url":"https://api.github.com/users/myitcv/orgs","repos_url":"https://api.github.com/users/myitcv/repos","events_url":"https://api.github.com/users/myitcv/events{/privacy}","received_events_url":"https://api.github.com/users/myitcv/received_events","type":"User","site_admin":false},"created_at":"2016-08-19T09:19:35Z","updated_at":"2016-08-19T09:19:35Z","body":"@jimmyfrasche \r\n\r\n> Optimizations is an interesting point, but I don't want to add that unless it actually happens\r\n\r\nConsider https://github.com/myitcv/sort_inlining_example\r\n\r\n[`main.go`](https://github.com/myitcv/sort_inlining_example/blob/master/main.go) is largely a copy and paste of un-exported parts of [`sort/sort.go`](https://github.com/golang/go/blob/master/src/sort/sort.go). Notice I've replaced use of `sort.Interface` with `[]string` directly. \r\n\r\n[`main_test.go`](https://github.com/myitcv/sort_inlining_example/blob/master/main_test.go) is a copy of `BenchmarkSortString1K` from [`sort/sort_test.go`](https://github.com/golang/go/blob/master/src/sort/sort_test.go)\r\n\r\n[`run.sh`](https://github.com/myitcv/sort_inlining_example/blob/master/run.sh) shows the setup.\r\n\r\n[`README.md`](https://github.com/myitcv/sort_inlining_example/blob/master/README.md) shows the output from `run.sh` (on my machine)\r\n\r\nNotice the inlining that can happen when the use `sort.Interface` is dropped.\r\n\r\nThis leads to a ~33% speedup in this benchmark.\r\n\r\n> Separating go generate from an editor macro is just editorializing for go generate, imo: everything that applies to one applies to the other. I mean yes it is great and good, but I am trying to keep that as neutral as it is possible for me in the interest of discussion.\r\n\r\ngo generate exists and is universally available to everyone via the go tool. The usage of the command is uniform and well documented.  \r\n\r\nWhilst some editors may have support for macros of this sort, these macros are not universally available (i.e. in all editors) and almost by definition usage of these macros is not uniform (i.e. it's different in each editor)\r\n\r\nHence why these should be considered very separately in my opinion. "}}
{"actor":{"display_login":"myitcv"}}