4 ms·
Wow, I'm not really interested in learning Go, but I was drawn in and made it all the way to learnInterfaces. Congrats! One question: why have named return val
by pjungwir 13y ago
Wow, I'm not really interested in learning Go, but I was drawn in and made it all the way to learnInterfaces. Congrats!
One question: why have named return values (in learnMemory) if you return something different? If you didn't have a return statement at all, would the function return the final value of p and q?
- jdiez17 13y ago>why have named return values (in learnMemory) if you return something different? Probably to avoid declaring the function as `func learnMemory() (int, int)`. >If you didn't have a return statement at all, would the function return the final value of p and q? No, you have to do that explicitly. You can do `return`, though, which will return the variables whose names match the definition.
- arnehormann 13y agoTo describe what you are returning. An int tells you a lot less than status404s int.
- stock_toaster 13y ago> One question: why have named return values (in learnMemory) if you return something different? If you didn't have a return statement at all, would the function return the final value of p and q? Kinda. You still have a return statement, but you may omit the arguments. See: http://golang.org/doc/effective_go.html#named-results http://golang.org/doc/effective_go.html#named-results
- pothibo 13y agoBecause the variable are already declared and ready to be used. Difference can be seen here → http://play.golang.org/p/IVPiw_2Uph http://play.golang.org/p/IVPiw_2Uph