{"action":"opened","issue":{"url":"https://api.github.com/repos/golang/go/issues/27460","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/27460/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/27460/comments","events_url":"https://api.github.com/repos/golang/go/issues/27460/events","html_url":"https://github.com/golang/go/issues/27460","id":356366920,"node_id":"MDU6SXNzdWUzNTYzNjY5MjA=","number":27460,"title":"[Language Change] Use unsigned integers for all lengths","user":{"login":"ProhtMeyhet","id":4989322,"node_id":"MDQ6VXNlcjQ5ODkzMjI=","avatar_url":"https://avatars2.githubusercontent.com/u/4989322?v=4","gravatar_id":"","url":"https://api.github.com/users/ProhtMeyhet","html_url":"https://github.com/ProhtMeyhet","followers_url":"https://api.github.com/users/ProhtMeyhet/followers","following_url":"https://api.github.com/users/ProhtMeyhet/following{/other_user}","gists_url":"https://api.github.com/users/ProhtMeyhet/gists{/gist_id}","starred_url":"https://api.github.com/users/ProhtMeyhet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ProhtMeyhet/subscriptions","organizations_url":"https://api.github.com/users/ProhtMeyhet/orgs","repos_url":"https://api.github.com/users/ProhtMeyhet/repos","events_url":"https://api.github.com/users/ProhtMeyhet/events{/privacy}","received_events_url":"https://api.github.com/users/ProhtMeyhet/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-03T05:57:12Z","updated_at":"2018-09-03T05:57:12Z","closed_at":null,"author_association":"NONE","body":"I propose for a future major update to use unsigned integers for all lengths. Values <0 had been used in other languages to indicate an error, but go has multiple return values and uses this extensively to return an error{} value besides actual function returns. As such negative values for indicating an error are not only unnecessary, but often plainly wrong. len() for example can't ever return -1 or <0:\r\n\r\n```go\r\nhello := \"multiverse\"\r\nlength := len(hello)\r\nt := reflect.TypeOf(length)\r\nfmt.Println(t.Name())  // prints: int\r\n```\r\nyes, this will require some rethinking, but maybe a few language additions can solve these cases. an easy corner case if len() would return uint is going through lists/arrays backwards:\r\n\r\ncurrently if len() were uint, this would not print index 0:\r\n```go\r\n\ta := []string{ \"1\", \"2\" }\r\n\tfor i := len(a)-1; i >= 0; i-- {\r\n\t\tfmt.Println(a[i])\r\n\t}\r\n```\r\ndirectly fixing it, however in a now unexpected way is possible:\r\n\r\n```go\r\na := []string{ \"1\", \"2\" }\r\nfor i := len(a)-1; ; i-- {\r\n\tfmt.Println(a[i])\r\n\tif i == 0 { break }\r\n}\r\n```\r\nbut since there is already range, go could then support reverse range:\r\n\r\n```go \r\na := []string{ \"1\", \"2\" }\r\nfor _, value := range a {\r\n\tfmt.Println(value)\r\n}\r\n\r\na := []string{ \"1\", \"2\" }\r\nfor _, value := reverse a {\r\n\tfmt.Println(value)\r\n}\r\n```\r\n\r\ni understand this proposal is controversial and would make go at a key, low level area behave vastly different then probably any other language, yet this would be correct and in order with go's other language tools (mostly multiple return values) and would make go more robust against errors caused by wrong return values and wrong assumptions."}}
{"actor":{"display_login":"ProhtMeyhet"}}