原文
Go's return values may be named. If so, they are treated as variables defined at the top of the function. These names should be used to document the meaning of the return values. A return statement without arguments returns the named return values. This is known as a "naked" return. Naked return statements should be used only in short functions, as with the example shown here. They can harm readability in longer functions. 複製代碼
代碼
package main
import "fmt"
func split(sum int) (x, y int) {
x = sum * 4 / 9
y = sum - x
return
}
func main() {
fmt.Println(split(17))
}
複製代碼
翻譯
Go函數的返回值能夠指名道姓。這些被指名道姓的返回值會當作變量聲明在函數的頂部
這些名稱應用於記錄返回值的含義
一個return語句後面啥都不寫,就像一個裸體return同樣
注意:裸return語句應該僅僅用在很短的函數內,就像這個例子同樣,在長函數當中,具備必定的損害可讀性
複製代碼
總結
整體來講,這個不建議使用,仍是別指名道姓了,讀取來挺費勁的。
複製代碼