{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/27794","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/27794/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/27794/comments","events_url":"https://api.github.com/repos/golang/go/issues/27794/events","html_url":"https://github.com/golang/go/issues/27794","id":362551431,"node_id":"MDU6SXNzdWUzNjI1NTE0MzE=","number":27794,"title":"proposal: Go 2: Conditional return and fallthrough cases","user":{"login":"l0k1verloren","id":20619963,"node_id":"MDQ6VXNlcjIwNjE5OTYz","avatar_url":"https://avatars2.githubusercontent.com/u/20619963?v=4","gravatar_id":"","url":"https://api.github.com/users/l0k1verloren","html_url":"https://github.com/l0k1verloren","followers_url":"https://api.github.com/users/l0k1verloren/followers","following_url":"https://api.github.com/users/l0k1verloren/following{/other_user}","gists_url":"https://api.github.com/users/l0k1verloren/gists{/gist_id}","starred_url":"https://api.github.com/users/l0k1verloren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/l0k1verloren/subscriptions","organizations_url":"https://api.github.com/users/l0k1verloren/orgs","repos_url":"https://api.github.com/users/l0k1verloren/repos","events_url":"https://api.github.com/users/l0k1verloren/events{/privacy}","received_events_url":"https://api.github.com/users/l0k1verloren/received_events","type":"User","site_admin":false},"labels":[{"id":150880249,"node_id":"MDU6TGFiZWwxNTA4ODAyNDk=","url":"https://api.github.com/repos/golang/go/labels/Go2","name":"Go2","color":"ffaaaa","default":false},{"id":236419512,"node_id":"MDU6TGFiZWwyMzY0MTk1MTI=","url":"https://api.github.com/repos/golang/go/labels/Proposal","name":"Proposal","color":"ededed","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/30","html_url":"https://github.com/golang/go/milestone/30","labels_url":"https://api.github.com/repos/golang/go/milestones/30/labels","id":1373555,"node_id":"MDk6TWlsZXN0b25lMTM3MzU1NQ==","number":30,"title":"Proposal","description":"Proposals that are pending (not yet accepted/rejected).\r\n","creator":{"login":"rsc","id":104030,"node_id":"MDQ6VXNlcjEwNDAzMA==","avatar_url":"https://avatars1.githubusercontent.com/u/104030?v=4","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":236,"closed_issues":599,"state":"open","created_at":"2015-10-24T01:40:49Z","updated_at":"2018-09-22T02:38:54Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2018-09-21T10:23:33Z","updated_at":"2018-09-22T02:44:41Z","closed_at":null,"author_association":"NONE","body":"There is two main threads in the discussions about improvements to Go to put into version 2, generics (*cough*) and error handling.\r\n\r\nThis is the latter.\r\n\r\nIn the most usual, and idiomatic pattern, error handling in Go looks like this:\r\n\r\n    result, err := DoSomething(With, These, 4, Parameters)\r\n    if err != nil {\r\n        return HideUnderTheTable(With, Friends)\r\n    }\r\n\r\nYou can shorten it to this:\r\n\r\n    if result, err := DoSomething(With, These, 4, Parameters); err != nil {\r\n        return HideUnderTheTable(With, Friends)\r\n    }\r\n\r\nBut what I am suggesting would look like this:\r\n\r\n    result, err := DoSomething(With, These, 4, Parameters);\r\n    return HideUnderTheTable(With, Friends) if err != nil\r\n\r\nSo it would be, as syntax:\r\n\r\n    return <statement> [if <condition>]\r\n\r\nOptionally the if block could exactly match the header of a standard if block, so this would be the syntax of return afterwards:\r\n\r\n    return <statement> [if [<statement>;] <condition]\r\n\r\nYou can also probably imagine these being used similarly to switch/cases like this:\r\n\r\n    buf := make([]byte, 32)\r\n    n, err := rand.Read(buf)\r\n    return err if err != nil\r\n    return errors.New(\"did not get 32 bytes\") if n != 32\r\n\r\nThese could be simplified by making the syntax a little different again for lists:\r\n\r\n    return (\r\n        <condition>: <statement>,\r\n        ....\r\n    )\r\n\r\nfollowing the convention for import, var, const, and others (and yes, maps). Or maybe parentheses would be more appropriate, but this would replace two or more conditional return statements.  These would behave a lot like switch statements but would specifically assist with error handling. \r\n\r\nAnd while I'm on returns, I think that the final return should be implicit with a named return variable.\r\n\r\nWhile I am talking about switch/case blocks, I think also that `fallthrough` should have a shorter form. Perhaps by adding 'if' as a possible label header, which implies fallthrouogh.\r\n\r\nI find myself using switches a lot and I think that if certain cases, such as the return, and the fallthrough, had more concise syntax, that people would use them and all the error handling gotchas could be eliminated."},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/423711245","html_url":"https://github.com/golang/go/issues/27794#issuecomment-423711245","issue_url":"https://api.github.com/repos/golang/go/issues/27794","id":423711245,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMzcxMTI0NQ==","user":{"login":"bcmills","id":5200974,"node_id":"MDQ6VXNlcjUyMDA5NzQ=","avatar_url":"https://avatars3.githubusercontent.com/u/5200974?v=4","gravatar_id":"","url":"https://api.github.com/users/bcmills","html_url":"https://github.com/bcmills","followers_url":"https://api.github.com/users/bcmills/followers","following_url":"https://api.github.com/users/bcmills/following{/other_user}","gists_url":"https://api.github.com/users/bcmills/gists{/gist_id}","starred_url":"https://api.github.com/users/bcmills/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcmills/subscriptions","organizations_url":"https://api.github.com/users/bcmills/orgs","repos_url":"https://api.github.com/users/bcmills/repos","events_url":"https://api.github.com/users/bcmills/events{/privacy}","received_events_url":"https://api.github.com/users/bcmills/received_events","type":"User","site_admin":false},"created_at":"2018-09-22T02:44:41Z","updated_at":"2018-09-22T02:44:41Z","author_association":"MEMBER","body":"CC: @mpvl "}}
{"actor":{"display_login":"bcmills"}}