- Key features of functions
- See also Methods doc
- An executable code block
- Multiple arguments
- Passed by value (or pass an address by value)
- varargs supported
- Multiple return types
- Passed by value (or pass an address by value)
- All types pass by value & return by value
- Some types pass by address value (feels like pass-by-reference)
- eg. map, slice, channel, pointer, function args
- See Language spec
- No overloading
- Same as C, javascript, typescript, Python, ...
- Unlike Java, C++, ...
- Use pointer receiver only when mutating
- TODO: (higher order) accepting function as arg
- TODO: (higher order) return a function
- TODO: defer - https://go.dev/ref/spec#Defer_statements
- TODO: named result param
- TODO: init function (per file)
- TODO: varargs
- TODO: it's ok to return address of local var in constructor