{"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":97,"created_at":"2016-08-16T04:52:44Z","updated_at":"2016-08-18T22:07:53Z","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/240872244","html_url":"https://github.com/golang/go/issues/16721#issuecomment-240872244","issue_url":"https://api.github.com/repos/golang/go/issues/16721","id":240872244,"user":{"login":"joshlf","id":1046063,"avatar_url":"https://avatars.githubusercontent.com/u/1046063?v=3","gravatar_id":"","url":"https://api.github.com/users/joshlf","html_url":"https://github.com/joshlf","followers_url":"https://api.github.com/users/joshlf/followers","following_url":"https://api.github.com/users/joshlf/following{/other_user}","gists_url":"https://api.github.com/users/joshlf/gists{/gist_id}","starred_url":"https://api.github.com/users/joshlf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshlf/subscriptions","organizations_url":"https://api.github.com/users/joshlf/orgs","repos_url":"https://api.github.com/users/joshlf/repos","events_url":"https://api.github.com/users/joshlf/events{/privacy}","received_events_url":"https://api.github.com/users/joshlf/received_events","type":"User","site_admin":false},"created_at":"2016-08-18T22:07:53Z","updated_at":"2016-08-18T22:07:53Z","body":"@jimmyfrasche My point was simply that if what I mentioned is a significant part of the concern, just adding that to the language would fix it and make the other problems that people have complained about not as bad (since they'd be the only issues left). In my experience, the headache that Brad referred to in the first comment (which I have definitely felt) stems largely from the namespacing issue. Also, I disagree that this should be Go 2 territory. Supporting methods on local types feels more similar in size to something like being able to use `v.method` as a closure - it would only expand the set of valid Go programs (thus maintaining the Go 1 compatibility guarantee), wouldn't be a particularly big change to the compiler, and wouldn't fundamentally change how any normal tasks are done in Go. \r\n\r\nAnyway, my point is simply that I do think this is relevant here because it's a possible alternative solution (although probably not the best solution proposed so far, I admit)."}}
{"actor":{"display_login":"joshlf"}}