Functions
Pass by value
- Go is a
pass by value
language. It means that when a function is called, the function receives a copy of the argument -
Any modifications made inside of the function do not affect the original variable outside of the function
-
Value Types
- In order to modify the original variable, pointers need to be manually specified by means of
&
and*
- int
- float
- string
- bool
- struct
-
array
-
Reference types
- Reference types are already references to an address in memory. Therefore there is usually no need to manipulate pointers with them, given that both copies point to the same underlying array
- Slice: has a
ptr to head
of the actual array, acapacity
and alength
- Map
- Channel
- Pointer
- Function
Function visibility
The naming of symbols in Go dictate the visibility of the symbol
PascalCase
is used for exported functions/symbols. Can be accessed from other packages.camelCase
for internal functions. Only visible for the current package.