#
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语句应该仅仅用在很短的函数内,就像这个例子一样,在长函数当中,具有一定的损害可读性
总结
总体来说,这个不建议使用,还是别指名道姓了,读取来挺费劲的。
文章永久链接:https://tech.souyunku.com/44581