It is just mind boggling how many different ways Go has for variable initialization. May be either i don't understand this completely or Go is a big after thought. Lot of things don't feel natural and looks like they added features as they found them missing. Initialization is one of them.
Here is running app on Go playground showing different ways of initialization
Here is what i understand
- There are values and pointers. Values are initiated using
var =
or:=
. -
:=
only works inside the methods - To Create value and reference you use new or
&
. And they only work on composite types. - There are whole new ways of creating maps and slices
- Create slice and maps using either make or var x []int. Noticing there is no
=
or:=
Are there any easy way to understand all this for newbies? Reading specs gives all this in bits and pieces everywhere.