Function and method
The procedural programming concept in Go.
Function
func main () {
}
Curly braces need to be on the same line:
func main ()
{
}
Argument & parameter
They're basically the same. Parameter is when defines, argument is when uses.
func main () {
num := 42
fooFunc(num)
}
func fooFunc (argument int) { // name followed by data type
println(argument)
}
You can shorten parameter list.
func fooFunc (arg1 int, arg2 int) {
}
// shortcut
func fooFunc (arg1, arg2 int) {
}
Returning result
Method
This is a little of object-oriented programming where we can add behaviors to the types that we create.