Go:名前付き戻り値
Go
の関数では戻り値に名前を設定しておくと return と書くだけで戻り値に設定される。偶然見つけたのでメモ。(naked returnというらしい)
code:go
func something(x, y int) (add, sub int) {
add = x + y
sub = x - y
return // add と sub が return される
}
なおこの記法は
golangci/golangci-lint
に搭載される
nakedret
で基本的にはブロックされる。
関連
Goの基本のキ
golangci-lint に搭載されている linter を学ぶ