What the different between those two Golang functions, are they the same with each other?
func foo1() (ret string) {
ret = "hi there"
return
}
func foo2() string {
ret := "hi there"
return ret
}
which is better?
CodePudding user response:
These two functions are identical: https://go.dev/play/p/_6KT5thL2Sj
foo2uses implicit return.foo1uses named return values andnaked/barereturn. Some consider this a code smell: proposal: Go 2: remove bare return
