Skip to content

Common variables declaration syntax #4

@lucasmenendez

Description

@lucasmenendez

Golang provides three syntaxes for the variable declaration:

  • The most comfortable way is foo := "foo" but with this syntax you probably makes mistakes like binary_address := []byte{0} (wallet.go:62) or s := "" (transaction.go:70).

  • Other way consists in using the keyword var to 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?

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions