Notes
Coddy - Go Lang Challenges
Go¶
Go compiles directly into machine code rather than relying on an interpreter like Python. It uses GoRoutines to handle numerous tasks at once.
Installing Go Lang¶
1) Install Go.
2) Type go version in terminal to verify installation.
3) Open VS Code and press Control + Shift + X.
4) Find the Go Extension.
5) Create a new folder and direct VSCode into it.
6) go mod init projectName.
Creates the
go.modfile which stores the name of the module, dependencies, and the go version. Its the Go equivalent ofpackage.jsonin NodeJS.
7) Create a new file inside the folder calledmain.go.
Variable Declaration¶
Standard¶
The standard declaration in Go uses the keyword var and requires types to be specified however they can be initialised without a value unlike shorthand.
Shorthand¶
Shorthand omits the var keyword and automatically infers variable type based on the value assigned to it.
My First Program¶
Hello World! Go Program
Different Bracket Style
While I typically like to use a style as demonstrated below in JS, I discovered in that semicolons are inserted automatically.