-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Golang provides three syntaxes for the variable declaration:
-
The most comfortable way is
foo := "foo"but with this syntax you probably makes mistakes likebinary_address := []byte{0}(wallet.go:62) ors := ""(transaction.go:70). -
Other way consists in using the keyword
varto the memory allocation and waits for the compiler to infer the variable type from the right side of declaration:var foo = "foo". I think its better way that the first one because allows to the developer to allocate memory without occupying them. -
The last way its an extended version of the second one that includes variable type:
var foo string = "foo". This way forces the developer to write more code, but make it more legible (and it's my favorite way).
What do you think about it?