Functions
Last updated
Last updated
A function can take 0 or more arguments. The type comes after the variable name, as mentioned before (same here for functions). The reason for that can be found here:
To be short, using the same example in the blog,
func main(argc int, argv []string) int
is a nice order because you can just read it off from this function declaration: function main takes an int and a slice of strings and returns an int.
A function can return any number of results. Return values may be named. If so, they are treated as variables defined at the top of the function.
A return
statement without arguments returns the named return values. This is called "naked" return.
Naked return statements should only be used in short functions. They hard readability in longer functions.