Diving into the Go language
Diving into the Go language 관련
Now that we've got the first notions in place, and we ran our first Hello, World! program, we can dive into the language.
The language has no semantically significant whitespace. This is like C, C++, Rust, Java, JavaScript, but unlike Python, where whitespace is meaningful and is used to create blocks instead of curly brackets.
Semicolons are optional, like in JavaScript (unlike in C, C++, Rust or Java).
Go takes indentation and visual order very seriously.
When we install Go we also get access to the gofmt
command line tool which we can use to format Go programs. VS Code uses that under the hood to format Go source files.
This is very interesting and innovative because formatting and issues like tabs vs spaces or “should I put the curly brackets on the same line of the loop definition or in the next line” are a huge waste of time.
The language creators defined the rules, and everyone uses those rules.
This is great for projects with large teams.
I recommend you enable in the VS Code Settings “Format on Save” and “Format on Paste”:
You can write comments in Go using the usual C / C++ / JavaScript / Java syntax:
// this is a line comment
/*
multi
line
comment
*/