Programming
Functions
A function can take zero or more arguments.
In this example, add takes two parameters of type int.
Notice that the type comes after the variable name.
When two or more consecutive named function parameters share a type, you can omit the type from all but the last.
In this example, we shortened
to
Multiple results
A function can return any number of results.
The swap function returns two strings.
Named return values
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.